Open failed: ENOENT (There is no such file or directory)

I have a problem loading an image that I get from shooting with a camera using the Android S3 azamon library.

To save the image

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 an image using 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 get the error Unable to calclualte MD5 hash:/file:/storage/sdcard0/DCIM/13161272646580.jpg open failed:ENOENT (No such file or directory)

but when I look at the sd card directory, I can find the image there (the image was created), and I created the appropriate permissions.

+7
source share
2 answers

The problem is your file path . Use this method to get the real way.

I will give you an example if you get an image from onActivityResult () you should have 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 it to 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 decided that it was. Hope this helps!

+2
source

I really don't remember what I did. But this is the code that I use that works. Hope this helps you guys!

 AmazonS3Client s3Client = new AmazonS3Client(new BasicAWSCredentials("XXX", "XXX")); String time = "" + System.currentTimeMillis(); PutObjectRequest por = new PutObjectRequest("fraternity", xyz_url_xyz + "/avatar" + time + ".jpg", new java.io.File(params[0])); por.setCannedAcl(CannedAccessControlList.PublicRead); s3Client.putObject(por); ResponseHeaderOverrides override = new ResponseHeaderOverrides(); override.setContentType("image/jpeg"); GeneratePresignedUrlRequest urlRequest = new GeneratePresignedUrlRequest("xyz_url_xyz/avatar.jpg"); urlRequest.setExpiration(new Date(System.currentTimeMillis() + 3600000)); urlRequest.setResponseHeaders( override ); s3Client.generatePresignedUrl(urlRequest); 
+1
source

All Articles