Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

S3 direct bucket upload: success but file not there

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.

like image 293
Balint Erdi Avatar asked Jun 09 '15 19:06

Balint Erdi


People also ask

Why can't I access an object that was uploaded to my Amazon S3 bucket by another AWS account?

For these existing buckets, an object owner had to explicitly grant permissions to an object (by attaching an access control list). Otherwise, the bucket owner would be unable to access the object. With S3 Object Ownership, bucket owners can now manage the ownership of any objects uploaded to their buckets.

Does S3 upload overwrite?

By default, when you upload the file with same name. It will overwrite the existing file. In case you want to have the previous file available, you need to enable versioning in the bucket.

Can S3 lose data?

Amazon states that “if you store 10,000,000 objects with Amazon S3, you can on average expect to incur a loss of a single object once every 10,000 years.” This is well beyond the risk level of “gravity randomly stops working.”

What is the maximum size of a file that you can upload to an Amazon S3 bucket?

Individual Amazon S3 objects can range in size from a minimum of 0 bytes to a maximum of 5 TB. The largest object that can be uploaded in a single PUT is 5 GB. For objects larger than 100 MB, customers should consider using the Multipart Upload capability.


1 Answers

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.

like image 182
Balint Erdi Avatar answered Sep 25 '22 01:09

Balint Erdi