以下是我的代码。我复制了可互操作的访问键。客户端和秘密都来自同一页面。我在表单中使用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)
我想使用HTML表单将文档上传到GCS。我已经创建了这个存储桶但我无法上传。我尝试了文档中给出的内容(https://developers.google.com/storage/docs/reference-methods#postobject),但仍然无法正常工作。 – user2131868 2013-05-05 09:58:50