S3 direct bucket upload: success but file not there

7.5k Views Asked by At

I'm uploading a file directly to an S3 bucket using a multipart form upload and a signed policy (with AWS Signature Version 2), as explained here and here.

The upload is successful (I get redirected to the success_action_redirect URL) but the file is not visible in the bucket, under the key it should be. Though the ACL of the uploaded file was set to public-read, I thought it might be a permission issue, but even the owner of the bucket does not see the file.

Does someone have a hint at might be wrong?

Thank you.

2

There are 2 best solutions below

0
On BEST ANSWER

Turns out that all I needed to do was to make sure that the uploaded filename is included in the key that was being uploaded to S3.

If you have a form like this:

<form action="http://johnsmith.s3.amazonaws.com/" method="post" enctype="multipart/form-data">
  <input type="input" name="key" value="user/eric/" /><br />
  (...)
</form>

Then the file will be uploaded to user/eric. What tripped me up is that the key defined this way was an existing S3 folder. AWS made it seem like the upload was successful but probably just dropped the uploaded files as the key already existed. The solution was to include the filename in the key thusly:

<form action="http://johnsmith.s3.amazonaws.com/" method="post" enctype="multipart/form-data">
  <input type="input" name="key" value="user/eric/${filename}" /><br />
  (...)
</form>

Also see the Upload examples docs.

0
On

Whenever we are uploading the small parts of file using presigned url, at that time it will upload that parts in temp location of AWS.

Once successfully uploaded all parts of file, perform the CompleteMultipartUploadRequest and it will store the your file in s3 bucket.

I hope it will work for you.

CompleteMultipartUploadResult multipartCompleteResult = null;

        List<PartETag> partETags = new new ArrayList<>();
        partETags.add(new new PartETag(partNumber1, eTag1));
        partETags.add(new new PartETag(partNumber2, eTag2));
        partETags.add(new new PartETag(partNumber3, eTag3));

        CompleteMultipartUploadRequest multipartCompleteRequest =
                new CompleteMultipartUploadRequest(getAmazonS3BucketName(), objectKey, uploadId, partETags);

        multipartCompleteResult = getAmazonS3Client().completeMultipartUpload(multipartCompleteRequest);