gpt4 book ai didi

google-cloud-storage - 无法使用发布方法将文件上传到谷歌云存储

转载 作者:行者123 更新时间:2023-12-02 08:41:05 26 4
gpt4 key购买 nike

下面是我的代码。我复制了可互操作的访问 key 。客户端和 secret 都来自同一页面。我在 ClientAccess ID 中使用了客户端 key 的形式和用于散列的 secret 。但是我收到错误消息说参数无效。

详细错误显示为“无法使用 POST 创建存储桶”

Below is the python code i used.

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)

最佳答案

我遇到了同样的问题,在尝试尽可能接近文档之后,我发现问题在于我的文件输入是表单的第一个子项而不是末尾。

有效:

<form action="https://***.storage.googleapis.com" method="post" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="hidden" name="signature" value="***" />
<input type="hidden" name="key" value="test/alexis.png" />
<input type="hidden" name="policy" value="***" />
<input type="hidden" name="Content-Type" value="image/png" />
<input type="hidden" name="GoogleAccessId" value="***@developer.gserviceaccount.com" />
<input type="hidden" name="bucket" value="***" />
<input type="hidden" name="success_action_status" value="201" />
<input type="submit" value="Upload">
</form>

作品:

<form action="https://***.storage.googleapis.com" method="post" enctype="multipart/form-data">
<input type="hidden" name="signature" value="***" />
<input type="hidden" name="key" value="test/alexis.png" />
<input type="hidden" name="policy" value="***" />
<input type="hidden" name="Content-Type" value="image/png" />
<input type="hidden" name="GoogleAccessId" value="***@developer.gserviceaccount.com" />
<input type="hidden" name="bucket" value="***" />
<input type="hidden" name="success_action_status" value="201" />
<input type="file" name="file" />
<input type="submit" value="Upload">
</form>

我仍然对为什么它以这种方式而不是另一种方式工作感到困惑......

关于google-cloud-storage - 无法使用发布方法将文件上传到谷歌云存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16378713/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com