gpt4 book ai didi

google-app-engine - 如何将 filepicker.io 与谷歌应用引擎 (blobstore) 集成?

转载 作者:太空宇宙 更新时间:2023-11-03 15:28:20 25 4
gpt4 key购买 nike

所以我正在尝试将 filepicker.io 与 GAE 应用程序一起使用。文件选择器小部件返回用户上传的文件的 URL。

然后我如何使用此 url 将文件上传到 GAE 的 blobstore?

blobstore 只支持“通过表单上传文件”,所以真正的问题是如何伪造一个包含文件 URL 的表单 POST。

最佳答案

伪造表单帖子是可能的,但使用 Files API 会简单得多

编辑:

要将 File API 与 urlfetch 结合使用,您需要编写如下内容:

from __future__ import with_statement
from google.appengine.api import files
from google.appengine.api import urlfetch

url = "http://www.facebook.com/somephoto.png"
result = urlfetch.fetch(url)
if result.status_code not 200:
return "some error"

# Create the file
file_name = files.blobstore.create(mime_type='application/octet-stream')

# Open the file and write to it
with files.open(file_name, 'a') as f:
f.write(result.content)

# Finalize the file. Do this before attempting to read it.
files.finalize(file_name)

# Get the file's blob key
blob_key = files.blobstore.get_blob_key(file_name)

我还没有对此进行测试 - 所以如果这不起作用,请告诉我。

此外,我相信您可以将 mime_type 保留为“application/octet-stream”,App Engine 将尝试猜测正确的类型。如果这不起作用,请尝试将其更改为“image/png”。或者对于 pdf,mime 类型将是 'application/pdf'

关于google-app-engine - 如何将 filepicker.io 与谷歌应用引擎 (blobstore) 集成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12149315/

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