4

I am trying to upload a Quicktime video to S3 but it is getting corrupted. I am using Java SDK. I assume that this is something to do with multipart? What do I need to do to stop it being corrupted. A file is being sent to S3 ok, but when downloaded and viewed it fails.

//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);
Zuriar
  • 11,096
  • 20
  • 57
  • 92
  • What is `picturePath`? Are you sure that the file is in that path? – RealSkeptic Nov 26 '19 at 16:35
  • just the path to the file - the file does get to S3 but it is corrupted – Zuriar Nov 26 '19 at 19:00
  • maybe this won't fix your issue, but *please* (ObjectMetadata).setContentLength() ([see here](https://stackoverflow.com/q/54379555/592355))! .... 2 cents on the "core problem": [`setContentMD5`](https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/model/ObjectMetadata.html#setContentMD5-java.lang.String-) ... "To ensure that data is not corrupted traversing the network, use the Content-MD5 header ..." ...might be helpful. – xerx593 Dec 02 '19 at 15:08
  • Also you might try setting content type to `application/octet-stream` – stirante Dec 02 '19 at 15:20

1 Answers1

1

From your question, I can't tell if you're using v1 or v2 of the AWS Java SDK.

I was able to find a similar issue where the user seemed to only be able to upload .mov files that were less than 5 MB in size. To upload files larger than 5 MB, you can try using Amazon's high-level multipart upload example that utilizes the TransferManager class, which is built-in to v1 of the AWS Java SDK.

With this, your code will look something like:

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();
}
Jacob G.
  • 28,856
  • 5
  • 62
  • 116