của nó có thể làm điều đó bằng hình thức dựa upload HTML: article này một công việc tốt giải thích nó như thế nào có khả năng. Sau khi đọc số article bạn có thể sử dụng các tập lệnh của tôi được đề cập bên dưới để làm cho cuộc sống dễ dàng hơn.
Đây là tập lệnh python mà tôi sử dụng để tạo chính sách, chữ ký và chuỗi base64 của tôi.
IMP: Đảm bảo rằng tệp policy.json là trong cùng thư mục
import base64
import hmac, hashlib
import os
AWS_SECRET_ACCESS_KEY = 'Your Access Key'
os.system('clear')
print "This policy generator is for key : " + AWS_SECRET_ACCESS_KEY
print "Make sure this is the correct key."
print "IMP: Please be consistent with the file policy.json small changes in space or newline can fail policy"
policy_document = file("policy.json",'rb').read()
policy = base64.b64encode(policy_document)
signature = base64.b64encode(hmac.new(AWS_SECRET_ACCESS_KEY, policy, hashlib.sha1).digest())
print
print "Policy (BASE64_POLICY to be inserted in HTML):-"
print policy
print
print "Signature:-"
print signature
print
Và đây là file policy.json tương ứng tôi sử dụng:
{
"expiration": "2014-01-01T00:00:00.00Z",
"conditions": [
{"bucket": "BUCKET NAME" },
["starts-with", "$key", "PREFIX_IF_ANY"],
{"acl": "public-read" },
{"success_action_redirect": "http://REDIRECTED_URL" },
["starts-with", "$Content-Type", "CONTENT_TYPE"],
["content-length-range", 0, 1048576],
]
}
HTML biểu mẫu cho mã này là như vậy:
<html>
<head>
<title>S3 POST Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action="http://BUCKET_NAME.s3.amazonaws.com/" method="post" enctype="multipart/form-data">
<input type="hidden" name="key" value="picbum/${filename}">
<input type="hidden" name="AWSAccessKeyId" value="AccessID">
<input type="hidden" name="acl" value="public-read">
<input type="hidden" name="success_action_redirect" value="http://REDIRECTED_URL">
<!-- Fill these HTML fields with data generated from python script -->
<input type="hidden" name="policy" value='BASE64_POLICY'>
<input type="hidden" name="signature" value="SIGNATURE_GENERATED">
<input type="hidden" name="Content-Type" value="CONTENT_TYPE">
<!-- Include any additional input fields here -->
File to upload to S3:
<input name="file" type="file">
<br>
<input type="submit" value="Upload File to S3">
</form>
</body>
</html>
Đây là lá phiếu của tôi vì bài viết giải thích mọi thứ. – Saeger