Amazon Simple Storage Service
API Reference (API Version 2006-03-01)

Examples: Browser-Based Upload using HTTP POST (Using AWS Signature Version 4)


File Upload

This example provides a sample POST policy and a form that you can use to upload a file. The topic uses the example policy and fictitious credentials to show you the workflow and resulting signature and policy hash. You can use this data as test suite to verify your signature calculation code.

The example uses the following example credentials the signature calculations. You can use these credentials to verify your signature calulation code. However, you must then replace these with your own credentials when sending requests to AWS.

Parameter Value

Sample Policy and Form

The following POST policy supports uploads to Amazon S3 with specific conditions.

{ "expiration": "2015-12-30T12:00:00.000Z", "conditions": [ {"bucket": "sigv4examplebucket"}, ["starts-with", "$key", "user/user1/"], {"acl": "public-read"}, {"success_action_redirect": ""}, ["starts-with", "$Content-Type", "image/"], {"x-amz-meta-uuid": "14365123651274"}, {"x-amz-server-side-encryption": "AES256"}, ["starts-with", "$x-amz-meta-tag", ""], {"x-amz-credential": "AKIAIOSFODNN7EXAMPLE/20151229/us-east-1/s3/aws4_request"}, {"x-amz-algorithm": "AWS4-HMAC-SHA256"}, {"x-amz-date": "20151229T000000Z" } ] }

This POST policy sets the following conditions on the request:

  • The upload must occur before noon UTC on December 30, 2015.

  • The content can be uploaded only to the sigv4examplebucket. The bucket must be in the region that you specified in the credential scope (x-amz-credential form parameter), because the signature you provided is valid only within this scope.

  • You can provide any key name that starts with user/user1. For example, user/user1/MyPhoto.jpg.

  • The ACL must be set to public-read.

  • If the upload succeeds, the user's browser is redirected to

  • The object must be an image file.

  • The x-amz-meta-uuid tag must be set to 14365123651274.

  • The x-amz-meta-tag can contain any value.

The following is a Base64-encoded version of this POST policy. You use this value as your StringToSign in signature calculation.


When you copy/paste the preceding policy, it should only have newlines (not carriage return and new line) for your computed hash to match this value.

Using example credentials to create a signature, the signature value is as follows (in signature calcuation, the date is same as the x-amz-date in the policy (20151229):


The following example form specifies the preceding POST policy and supports a POST request to the sigv4examplebucket. Copy/paste the content in a text editor and save it as exampleform.html. You can then upload image files to the specific bucket using the exampleform.html. You request will succeed if you signature you provide matches the signature Amazon S3 calculates.


You must update the bucket name, dates, credential, policy, and signature with valid values for this to successfully upload to S3.

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <form action="" method="post" enctype="multipart/form-data"> Key to upload: <input type="input" name="key" value="user/user1/${filename}" /><br /> <input type="hidden" name="acl" value="public-read" /> <input type="hidden" name="success_action_redirect" value="" /> Content-Type: <input type="input" name="Content-Type" value="image/jpeg" /><br /> <input type="hidden" name="x-amz-meta-uuid" value="14365123651274" /> <input type="hidden" name="x-amz-server-side-encryption" value="AES256" /> <input type="text" name="X-Amz-Credential" value="AKIAIOSFODNN7EXAMPLE/20151229/us-east-1/s3/aws4_request" /> <input type="text" name="X-Amz-Algorithm" value="AWS4-HMAC-SHA256" /> <input type="text" name="X-Amz-Date" value="20151229T000000Z" /> Tags for File: <input type="input" name="x-amz-meta-tag" value="" /><br /> <input type="hidden" name="Policy" value='<Base64-encoded policy string>' /> <input type="hidden" name="X-Amz-Signature" value="<signature-value>" /> File: <input type="file" name="file" /> <br /> <!-- The elements after this will be ignored --> <input type="submit" name="submit" value="Upload to Amazon S3" /> </form> </html>

The post parameters are case insensitive. For example, you can specify x-amz-signature or X-Amz-Signature.

On this page: