简体   繁体   English

打开失败:ENOENT(没有此类文件或目录)错误

[英]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. 我试图通过使用亚马逊S3安卓库来上传使用相机拍照的照片时遇到问题。

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: 要使用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) 我一直收到错误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. 但是当我浏览我的SD卡目录时,我可以在那里找到图片(图片已经创建),并且我已经创建了相关的权限。

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. 我给你举个例子,如果你从onActivityResult()获取图像你应该有一个onActivityResult(int requestCode,int resultCode,Intent data),你可以在其中获得你的图像的Uri。

Uri uri = data.getData(); 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); 然后你使用它并从Uri获取真实路径并将其传递给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! 希望能帮助到你!

I don't really remember what I did. 我真的不记得我做了什么。 But this is the code I use that works. 但这是我使用的代码。 Hope it can help 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:打开失败:ENOENT(没有那个文件或目录) - Error: open failed: ENOENT (No such file or directory) Android:打开失败:ENOENT(无此类文件或目录)错误 - Android: open failed: ENOENT (No such file or directory) Error fileInputStream(file)提供打开失败:ENOENT(无此类文件或目录)错误 - fileInputStream(file) gives open failed: ENOENT (No such file or directory) error 要将图像发布到Twitter中,得到错误:打开失败:ENOENT(无此文件或目录) - To post the image in twitter,getting Error:open failed: ENOENT (No such file or directory) Android:NDK:超级打开失败:ENOENT(没有这样的文件或目录)错误 - Android : NDK : Superpowered Open failed: ENOENT (No such file or directory) Error 写入存储打开失败时出错:android 中的 ENOENT (No such file or directory) - Error while writing storage open failed: ENOENT (No such file or directory) in android BitmapFactory 打开失败:ENOENT(没有那个文件或目录) - BitmapFactory open failed: ENOENT (No such file or directory) Android解压缩失败:ENOENT(无此文件或目录) - Android unzip open failed: ENOENT (No such file or directory) Android:打开失败:ENOENT没有这样的文件或目录 - Android: open failed: ENOENT No such file or directory createNewFile - 打开失败:ENOENT(没有这样的文件或目录) - createNewFile - open failed: ENOENT (No such file or directory)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM