【问题标题】:Upload to Google Cloud Storage上传到谷歌云存储
【发布时间】:2014-10-07 16:30:11
【问题描述】:

我正在尝试从我的应用引擎应用上传到云存储,但它一直在上传文件的名称而不是其内容。

html 很简单:

<form id="uploadbanner" enctype="multipart/form-data" action="/upload">
    <input id="fileupload" name="myfile" type="file" />
    <input type="submit" value="submit" id="submit" />
</form>

python 元素是这样的:

class Uploader(webapp2.RequestHandler):
def get(self):
    objectname = '%s'%str(uuid.uuid4())
    objectpath = '/gs/bucketname/%s' %objectname
    upload = self.request.get('myfile')
    writable = files.gs.create(filename=objectpath, mime_type='application/octet-stream', acl='public-read')
    with files.open(writable, 'a') as f:
        f.write(upload)
    files.finalize(writable)
    self.response.write('done')

我知道f.write(upload) 肯定是错的,但我不知道应该用什么替换它

【问题讨论】:

    标签: google-app-engine google-cloud-storage google-api-python-client


    【解决方案1】:

    您可能应该让浏览器直接上传到 GCS,然后才调用您的处理程序。

    要简要了解如何做到这一点,请查看此帖子:Upload images/video to google cloud storage using Google App Engine

    即使在此示例中似乎调用了 blobstore API,文件也会上传到 Cloud Storage。

    【讨论】:

      【解决方案2】:

      它需要是 POST 而不是 GET,所以在表单中添加method="POST" 并让 python 函数 post 而不是 get,这对我来说已经解决了。

      【讨论】:

        猜你喜欢
        • 2021-06-09
        • 2018-09-18
        • 1970-01-01
        • 1970-01-01
        • 2016-12-30
        • 2015-03-01
        • 2021-06-15
        • 2016-07-31
        • 2020-07-04
        相关资源
        最近更新 更多