使用Java SDK将Quicktime视频上传到S3

时间:2019-11-26 15:57:01

标签: java amazon-s3

我正在尝试将Quicktime视频上传到S3,但是它已损坏。我正在使用Java SDK。我认为这与多部分有关?我需要做些什么来阻止它被损坏。文件正在发送到S3,但下载和查看失败。

//upload video to S3
    PutObjectRequest request2 = new PutObjectRequest(bucketName, "movie.mov", new File(picturePath + "/" + "movie.mov"));

    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentType("video/quicktime");
    request2.setMetadata(metadata);

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

1 个答案:

答案 0 :(得分:1)

根据您的问题,我无法确定您使用的是AWS Java SDK的v1还是v2

我能够找到一个similar issue,用户似乎只能上载小于5 MB的.mov文件。要上传大于5 MB的文件,您可以尝试使用利用TransferManager类的Amazon high-level multipart upload example,该类内置于AWS Java SDK v1。

这样,您的代码将类似于:

try {
    TransferManager tm = TransferManagerBuilder.standard()
            .withS3Client(s3Client)
            .build();

    // TransferManager processes all transfers asynchronously,
    // so this call returns immediately.
    Upload upload = tm.upload(bucketName, "movie.mov", 
        new File(picturePath + "/" + "movie.mov"));
    System.out.println("Object upload started");

    // Optionally, wait for the upload to finish before continuing.
    upload.waitForCompletion();
    System.out.println("Object upload complete");
} catch (AmazonServiceException e) {
    // The call was transmitted successfully, but Amazon S3 couldn't process 
    // it, so it returned an error response.
    e.printStackTrace();
} catch (SdkClientException e) {
    // Amazon S3 couldn't be contacted for a response, or the client
    // couldn't parse the response from Amazon S3.
    e.printStackTrace();
}