无法使用发布方法将文件上传到Google云存储 [英] Unable to upload file to google cloud storage using post method

查看:104
本文介绍了无法使用发布方法将文件上传到Google云存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的代码.我复制了可互操作的访问密钥.客户端和密钥都来自同一页面.我在ClientAccess ID中以格式使用了客户端密钥,并使用了秘密进行哈希处理. 但是我收到错误消息说无效的参数.

Below is my code. I copied the interoperable access keys.. The client and secret both from the same page. I used client key in the ClientAccess ID in the form and secret for hashing. But i get the error saying invalid argument.

详细信息错误显示为无法使用POST创建存储桶"

下面是我使用的python代码.

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)

推荐答案

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

I had the same issue, and after trying to be as close as possible to the documentation, I found that what was wrong is that my file input was the first child of the form instead of at the end.

有效:

<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>

我仍然对为什么它能以这种方式而不是其他方式感到困惑...

I'm still puzzled about why it works this way and not the other...

这篇关于无法使用发布方法将文件上传到Google云存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆