无法将图像上传到AWS S3 [英] Failed to Upload image to aws s3

查看:206
本文介绍了无法将图像上传到AWS S3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

/*捕获图像并将其传递给AWS示例代码以上传到s3存储桶.*/

/* Capturing an image and passing it to aws sample code to upload to s3 bucket.*/

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent resultData) {
    super.onActivityResult(requestCode, resultCode, resultData);

    if (resultData != null) {

        String[] projection = {MediaStore.Images.Media.DATA};
        Cursor cursor = managedQuery(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                projection, null, null, null);
        int column_index_data = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToLast();

        String uri = cursor.getString(column_index_data);
        Bitmap bitmapImage = BitmapFactory.decodeFile(uri);
        iv.setImageURI(parse(uri));

        System.out.print(uri);
        Log.e("Uri", String.valueOf(uri));
        Upload_image upload = new Upload_image(activity);

        upload.beginUpload(uri);
    }
}

/*使用Asynctask来上传到s3,因为主线程越来越重*/

/* using Asynctask to upload to s3 as main Thread is getting heavy*/

class UploadFilesTask extends AsyncTask<String , Integer, String> {
    String filepath;
    public  UploadFilesTask(String filepath){this.filepath = filepath;}
    @Override
    protected String doInBackground(String... params) {
        File file = new File(filepath);

        TransferObserver observer = transferUtility.upload(Constants.BUCKET_NAME, file.getName(),
                file);
        return null;
    }

/* logcat响应:当我尝试上传而没有任何错误时失败

/* logcat response : fails when i try to upload without any error

16:54:48.064 2424-2424/com.example.rinzinchoephel.drivervolley E/Uri: /storage/emulated/0/DCIM/Camera/IMG_20160921_165440968.jpg

                                                                            [ 09-21 16:54:48.246  2424: 2424 W/         ]
                                                                            Unable to open '/system/framework/prcui-config.jar': No such file or directory
09-21 16:54:48.246 2424-2424/com.example.rinzinchoephel.drivervolley W/art: Failed to open zip archive '/system/framework/prcui-config.jar': I/O Error

                                                                            [ 09-21 16:54:48.248  2424: 2424 W/         ]
                                                                            Unable to open '/system/framework/prcui-config.jar': No such file or directory
09-21 16:54:48.248 2424-2424/com.example.rinzinchoephel.drivervolley W/art: Failed to open zip archive '/system/framework/prcui-config.jar': I/O Error
09-21 16:54:48.259 2424-2424/com.example.rinzinchoephel.drivervolley D/CognitoCachingCredentialsProvider: Loading credentials from SharedPreferences

                                                                                                          [ 09-21 16:54:48.267  2424: 2424 W/         ]
                                                                                                          Unable to open '/system/framework/prcui-config.jar': No such file or directory
09-21 16:54:48.267 2424-2424/com.example.rinzinchoephel.drivervolley W/art: Failed to open zip archive '/system/framework/prcui-config.jar': I/O Error

                                                                            [ 09-21 16:54:48.269  2424: 2424 W/         ]
                                                                            Unable to open '/system/framework/prcui-config.jar': No such file or directory
09-21 16:54:48.269 2424-2424/com.example.rinzinchoephel.drivervolley W/art: Failed to open zip archive '/system/framework/prcui-config.jar': I/O Error
09-21 16:54:48.280 2424-4787/com.example.rinzinchoephel.drivervolley E/asyncfilePath: /storage/emulated/0/DCIM/Camera/IMG_20160921_165440968.jpg
09-21 16:54:48.280 2424-4787/com.example.rinzinchoephel.drivervolley E/asyncfilegetName: IMG_20160921_165440968.jpg
09-21 16:54:48.280 2424-4787/com.example.rinzinchoephel.drivervolley E/asyncTranUtility: com.amazonaws.mobileconnectors.s3.transferutility.TransferUtility@374bc1e
09-21 16:54:48.339 2424-2424/com.example.rinzinchoephel.drivervolley D/TransferService: Starting Transfer Service
09-21 16:54:48.909 2424-2424/com.example.rinzinchoephel.drivervolley D/TransferService: Network connected: true
09-21 16:54:48.909 2424-2424/com.example.rinzinchoephel.drivervolley I/Choreographer: Skipped 32 frames!  The application may be doing too much work on its main thread.
09-21 16:54:48.910 2424-4788/com.example.rinzinchoephel.drivervolley D/TransferService: Loading transfers from database
09-21 16:54:48.912 2424-4788/com.example.rinzinchoephel.drivervolley D/TransferService: 0 transfers are loaded from database
09-21 16:55:48.969 2424-4788/com.example.rinzinchoephel.drivervolley D/TransferService: Stop self

推荐答案

使用本机意图获取图像时,它将返回原始图像.图片大小过大(将近2MB),最好将其压缩并上传.

While getting images using native intents it will return original image. Image size is too large (nearly 2MB) better compress the image and upload it.

ByteArrayOutputStream bytes = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.PNG, 80, bytes);

更多详细信息,请检查此链接: http://droidmentor.com/pick-image-from-gallery-or-相机/

Further details check this link: http://droidmentor.com/pick-image-from-gallery-or-camera/

这篇关于无法将图像上传到AWS S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆