Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

open failed:ENOENT (No such file or directory) error

I've got a problem trying to upload an image I get from taking a picture with the camera,using amazon S3 android library.

To save the picture

File _photoFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),   (cal.getTimeInMillis() + ".jpg"));

            try {
                if (_photoFile.exists() == false) {
                    _photoFile.getParentFile().mkdirs();
                    _photoFile.createNewFile();
                }

            } catch (IOException e) {
                // Log.e(TAG, "Could not create file.", e);
            }
            // Log.i(TAG, path);

            filePath = Uri.fromFile(_photoFile);
            Intent cameraIntent = new Intent(
                    android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, filePath);
            startActivityForResult(cameraIntent, 1);

To upload the picture with the filePath:

try {
            s3Client.createBucket(Constants.getPictureBucket());

            // Content type is determined by file extension.
            PutObjectRequest por = new PutObjectRequest(
                    Constants.getPictureBucket(), Constants.PICTURE_NAME,
                    new java.io.File(filePath));
            s3Client.putObject(por);
        } catch (Exception exception) {

            result.setErrorMessage(exception.getMessage());
        }

I keep getting an error Unable to calclualte MD5 hash:/file:/storage/sdcard0/DCIM/13161272646580.jpg open failed:ENOENT (No such file or directory)

but when I browse my sd card's directory I can find the picture there(the picture has been created), and I've created the relevant permissions.

like image 553
fizo07 Avatar asked Feb 19 '13 11:02

fizo07


People also ask

What is ENOENT error Android?

The ENOENT (No such file or directory) error may occur in application, If the application do not have storage permission. We suggest you to ensure whether the application has storage permission to read and write file in storage location. We have modified sample to provide storage permission at run time.

What is Enoent?

The enoent meaning error no entry.


1 Answers

The problem is in your file path. Use a method like that to get the Real Path.

I give you an example, if you are getting the image from onActivityResult() You should have a onActivityResult(int requestCode, int resultCode, Intent data) where you can get the Uri of your image.

Uri uri = data.getData();

Then you use it and get the real path from Uri and pass this to the PutObjectRequest(BUCKET_NAME, IMAGE_NAME, REAL_PATH);

public String getRealPathFromURI(Context context, Uri contentUri) {
    Cursor cursor = null;
    try {
        String[] proj = { MediaStore.Images.Media.DATA };
        cursor = context.getContentResolver().query(contentUri,  proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

I had the same problem and I solve it doing this. Hope it helps!

like image 173
Renan Grativol Avatar answered Sep 20 '22 06:09

Renan Grativol