android - 从 Android 应用程序将视频上​​传到 S3 AWS 会生成一个 0Kb 文件

标签 android video file-upload amazon-web-services amazon-s3

我的 Android 应用程序可以将相机直接拍摄的照片或从图库中选择的照片上传到 S3 AWS。现在我希望该应用程序也可以从图库上传视频。但是上传的文件大小总是0Kb。

这是视频选择过程的代码:

Intent videoPickerIntent = new Intent(Intent.ACTION_PICK);
videoPickerIntent.setType("video/*");
getActivity().startActivityForResult(videoPickerIntent, SELECT_VIDEO);

然后,我得到了视频路径(我已经测试了我在同一个应用程序的 VideoView 中播放视频的路径)。 (示例:“/storage/emulated/0/DCIM/Camera/VID_20140903_163147.mp4”)

最后,我在 AsyncTask 中使用 PutObjectRequest,类似于我上传照片的方式。

PutObjectRequest por = new PutObjectRequest(bucket, nameInAwsWithPath, videoPath);
por.setCannedAcl(CannedAccessControlList.PublicRead);
s3Client.putObject(por);

然后,在 S3 中,我可以看到一个按预期命名但为空的文件。 0 KB 大小。

出了什么问题?

最佳答案

这是代码:

private class S3PutVideoTask extends AsyncTask<String, Integer, Boolean> {

        ProgressDialog dialog;

        protected void onPreExecute() {
            dialog = new ProgressDialog(getActivity());
            dialog.setMessage(getString(R.string.uploadingvideo));
            dialog.setCancelable(false);
            dialog.show();
        }

        protected Boolean doInBackground(String... params) {

            boolean result = true;
            // Put the video data into S3.
            try {

                PutObjectRequest por;

                String filename = "img_" + xxxxx[pos].id + "_"
                        + System.currentTimeMillis() + ".avi";

                File fileToUpload = new File(mCurrentAbsoluteVideoPath);

                SharedPreferences prefs = getActivity().getSharedPreferences("GlobalPrefs", Context.MODE_PRIVATE);
                String bucket = prefs.getString("bucket", PICTURE_BUCKET);

                por = new PutObjectRequest(bucket, filename, fileToUpload);

                por.setCannedAcl(CannedAccessControlList.PublicRead);
                s3Client.putObject(por);

            } catch (Exception exception) {

                result = false;
            }

            return result;
        }

        @Override
        protected void onPostExecute(Boolean result) {

            dialog.dismiss();

            if (!result) {
                //show error
            } else {
                fileUploaded = true;
                dismissUpload();
            }
        }
    }

关于android - 从 Android 应用程序将视频上​​传到 S3 AWS 会生成一个 0Kb 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25669766/

相关文章:

android - java.lang.OutOfMemoryError : bitmap size exceeds VM budget on line Drawable. createFromStream(((java.io.InputStream) new URL(url), "") 在android中

android - 错误 :Execution failed for task ':app:transformClassesWithJarMergingForDebug'

android - Firebase 分析 AppMeasurement 未启用

css - 自举 |两列一列 16 :9 video and some text

video - 如何使用Hadoop处理视频数据

c# - 附件不发送 ASP.NET MVC

javascript - Rails 部署时 Jquery 文件上传功能不起作用

android - 使用recyclerview android过滤男性和女性结果searchview

video - (FFMPEG) 在用透视图覆盖视频之前使区域透明

asp.net-mvc-4 - 如果超过特定大小限制,如何阻止文件上传?