javascriptamazon-s3xmlhttprequest

How to upload file to S3 without AWS JavaScript SDK?


AWS SDK for JavaScript (even if only the S3 component is included) is a huge bulk for just some sporadic file uploads in my webapp. Is there a leaner way to upload files to an S3 bucket directly from the client's browser, given that I have the bucket name, accessKeyId and secretAccessKey at my disposal?


Solution

  • S3 supports uploads from the browser using a form post upload, with no special code needed at the browser. It involves a specific design of form and a signed policy document that allows the user to only upload files matching constraints you impose, and doesn't expose your secret key. It will optionally also redirect the browser back to your site after the upload.

    http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-post-example.html