Python uploads files on HTTP POST to S3 cloud service in Browser

Source: Internet
Author: User
Tags base64 hmac http post


We can construct a pre-approved HTTP POST form in the HTTP page to upload files to S3 using post in the browser side. The contents of the form are as follows:


where value= "Upload/${filename}" is the destination address, the directory automatically creates
Name= "Success_action_redirect value=" http:// Your-success-page ", after the successful upload of the jump page
name=" policy "value=" XXXX "with Base64 encrypted policy string
Name=" signature "value=" xxxx " , use the Base64 encrypted signature with Secret_key
Encryption algorithm is the following Python version:

Import Base64
import HMAC, hashlib
Aws_secret_access_key = r "xxxxxx"
policy_document = "'
{
" Expiration ":" 2020-01-01t00:00:00z ","
conditions ": [
{" Bucket ":" Your-bucket "},
[" Starts-with "," $ Key "," "],
{" ACL ":" Private "},
{" Success_action_redirect ":" Http://your-success-page "},
[" starts- With "," $Content-type "," "],
[" Content-length-range ", 0, 1048576000]
]
}
" '
policy = base6 4.b64encode (policy_document)
signature = Base64.b64encode (Hmac.new, Aws_secret_access_key, HASHLIB.SHA1). Digest ())
Print policy
print signature


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.