其可能使用基於HTML表單的上傳做到這一點:這article沒有很好地解釋瞭如何是可能的。在閱讀article之後,您可以使用下面提到的腳本來簡化生活。
這是一個用於生成我的策略,其簽名和base64字符串的python腳本。
IMP:確保policy.json文件在同一目錄
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
,這裏是相應的policy.json文件我用:
{
"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這種代碼的形式是這樣的:
<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>
來源
2013-09-19 18:01:58
MaK
這是我的投票,因爲文章解釋每一個。 – Saeger 2015-03-26 18:34:23