I tried using Boto, but found that it does not allow me to put all the headers I wanted. Below you can see what I'm doing to create a post form policy, signature and dictionary of values.
Note that all x-amz-meta- * tags are custom header properties and you do not need them. Also note that almost everything that will be on the form should be in a policy that is encoded and signed.
def generate_post_form(bucket_name, key, post_key, file_id, file_name, content_type): import hmac from hashlib import sha1 from django.conf import settings policy = """{"expiration": "%(expires)s","conditions": [{"bucket":"%(bucket)s"},["eq","$key","%(key)s"],{"acl":"private"},{"x-amz-meta-content_type":"%(content_type)s"},{"x-amz-meta-file_name":"%(file_name)s"},{"x-amz-meta-post_key":"%(post_key)s"},{"x-amz-meta-file_id":"%(file_id)s"},{"success_action_status":"200"}]}""" policy = policy%{ "expires":(datetime.utcnow()+settings.TIMEOUT).strftime("%Y-%m-%dT%H:%M:%SZ"), # This has to be formatted this way "bucket": bucket_name, # the name of your bucket "key": key, # this is the S3 key where the posted file will be stored "post_key": post_key, # custom properties begin here "file_id":file_id, "file_name": file_name, "content_type": content_type, } encoded = policy.encode('utf-8').encode('base64').replace("\n","") # Here we base64 encode a UTF-8 version of our policy. Make sure there are no new lines, Amazon doesn't like them. return ("%s://%s.s3.amazonaws.com/"%(settings.HTTP_CONNECTION_TYPE, self.bucket_name), {"policy":encoded, "signature":hmac.new(settings.AWS_SECRET_KEY,encoded,sha1).digest().encode("base64").replace("\n",""), # Generate the policy signature using our Amazon Secret Key "key": key, "AWSAccessKeyId": settings.AWS_ACCESS_KEY, # Obviously the Amazon Access Key "acl":"private", "x-amz-meta-post_key":post_key, "x-amz-meta-file_id":file_id, "x-amz-meta-file_name": file_name, "x-amz-meta-content_type": content_type, "success_action_status":"200", })
Then, the returned tuple can be used to create a form that submits to the generated S3 URL with all pairs of key values โโfrom the dictionary in the form of hidden fields and your actual file input field, whose name should be "file".
Hope this helps as an example.