[英]Getting a file with urlfetch and saving it to the Google datastore
我已阅读在GAE和Google App Engine中 从urlfetch打开文件 ,如何制作本机文件对象? 但仍然不知道如何将.pdf文件从网址保存到Google数据存储区或Blob存储区。 有任何提示或指向可行示例的指针吗?
我正在使用Python,而我的代码本质上是来自https://developers.google.com/appengine/docs/python/urlfetch/?hl=it-IT&csw=1的代码
from google.appengine.api import urlfetch
url = "http://www.gutenberg.org/files/1342/1342-pdf.pdf"
result = urlfetch.fetch(url)
if result.status_code == 200:
doSomethingWithResult(result.content)
就像是
首先,您的模型将PDF存储在
class PDFStore(ndb.Model):
content = ndb.BlobProperty()
创建该模型的实例,然后将数据放入其中并保存。
def doSomethingWithResult(result):
PDF = result.content
blobstore_data = PDFStore()
blobstore_data.content = PDF
blobstore_data.put()
与您建立的第一个链接完全相同: 在GAE中从urlfetch打开文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.