Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google app engine 如何将filepicker.io与google应用程序引擎(blobstore)集成?_Google App Engine_Google Cloud Datastore_Blobstore_Webapp2_Filepicker.io - Fatal编程技术网

Google app engine 如何将filepicker.io与google应用程序引擎(blobstore)集成?

Google app engine 如何将filepicker.io与google应用程序引擎(blobstore)集成?,google-app-engine,google-cloud-datastore,blobstore,webapp2,filepicker.io,Google App Engine,Google Cloud Datastore,Blobstore,Webapp2,Filepicker.io,因此,我尝试将filepicker.io与GAE应用程序一起使用。filepicker小部件返回用户上载的文件的URL 然后如何使用此url将文件上载到GAE的blobstore blobstore只支持“通过表单上传文件”,因此真正的问题是如何伪造包含文件URL的表单帖子。伪造表单帖子是可能的,但使用 编辑: 要将文件API与urlfetch一起使用,您可以编写如下内容: from __future__ import with_statement from google.appengine.a

因此,我尝试将filepicker.io与GAE应用程序一起使用。filepicker小部件返回用户上载的文件的URL

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


blobstore只支持“通过表单上传文件”,因此真正的问题是如何伪造包含文件URL的表单帖子。

伪造表单帖子是可能的,但使用

编辑:

要将文件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_类型保留为“application/octet stream”,App引擎将尝试猜测正确的类型。如果不起作用,请尝试将其更改为“image/png”。或者对于pdf来说,mime类型应该是“application/pdf”

我们实际上花了很多时间试图找到是否可以绕过浏览器来伪造您描述的内容,但是没有用。我的建议是编写一些快速的后端代码,如Kyle建议的从url抓取文件对象,但是如果您真的是持久的,您实际上可以使用ajax伪造您自己的多部分表单请求


请参阅并获取一些关于如何实现这一点的想法,最热门答案中的files API已被弃用,因此我在github上编写了一个要点来解决这个问题。它获取图像的url,并使用请求和海报将其发布到您自己的服务器


哦,我在看这个,但是你如何将pdf的内容写入blob对象呢?它似乎只支持文本。啊,酷,它的作品!但是文件正在下载(一旦你在url上查看),没有扩展名,所以你不可能知道它是.pdf。有没有办法附加文件扩展名?@jellyksong从Blobstore提供服务时,是否要添加.pdf?你能为这个问题提出一个新问题吗?请包括您用于服务器文件的代码。