下面是我的代码。我复制了可互操作的访问密钥。客户端和机密都来自同一页面。我在 ClientAccess ID 中使用客户端密钥和密钥进行散列。但我得到错误说无效的论点。
详细错误显示为“无法使用 POST 创建存储桶”
下面是我使用的python代码。
import webapp2
import cgi
import datetime
import urllib
import base64
import hmac, hashlib
import sha
policy_document = '''{"expiration": "2016-06-16T11:11:11Z",
"conditions": [
["starts-with", "$key", "" ],
{"acl": "public-read" },
]
}'''
policy = base64.b64encode(policy_document).strip()
h = hmac.new('xxx', digestmod=sha.sha)
h.update(policy)
signature = base64.b64encode(h.digest())
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write('<html><body>')
self.response.write('<form action="http://storage.googleapis.com/www.xyz.com" method="post" enctype="multipart/form-data">')
self.response.write('<input type="text" name="key" value="">')
self.response.write('<input type="hidden" name="bucket" value="www.xyz.com">')
#self.response.write('<input type="hidden" name="Content-Type" value="image/jpeg">')
self.response.write('<input type="hidden" name="GoogleAccessId" value="GOOGxxxxx">')
self.response.write('<input type="hidden" name="acl" value="public-read">')
self.response.write('<input type="hidden" name="success_action_redirect" value="http://www.linklip.com/storage.html">')
self.response.write('<input type="hidden" name="policy" value="%s">' % policy )
self.response.write('<input type="hidden" name="signature" value="%s">' % signature )
self.response.write('<input name="file" type="file">')
self.response.write('<input type="submit" value="Upload">')
self.response.write('</form>')
self.response.write('</body></html>')
app = webapp2.WSGIApplication([
('/', MainHandler)
], debug=True)