【问题标题】:Getting a file with urlfetch and saving it to the Google datastore使用 urlfetch 获取文件并将其保存到 Google 数据存储区
【发布时间】:2013-12-23 15:51:30
【问题描述】:

我已阅读 Open a file from urlfetch in GAEGoogle App Engine, How to make native file object?,但仍不知道如何将 .pdf 文件从 URL 保存到 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)

【问题讨论】:

    标签: google-app-engine python-2.7 google-cloud-datastore blobstore urlfetch


    【解决方案1】:

    类似

    首先将您的模型存储在其中

    class PDFStore(ndb.Model):
      content = ndb.BlobProperty()
    

    创建该模型的实例,将数据放入其中并保存。

    def doSomethingWithResult(result):
        PDF = result.content
    
        blobstore_data = PDFStore()
    
        blobstore_data.content = PDF
    
        blobstore_data.put()
    

    与您发布的第一个链接完全相同:Open a file from urlfetch in GAE

    【讨论】:

    • 变量名混淆。由于 BlobStore 是 blob 的集合,PDFStore 将是 PDF 的集合。 blobstore_data 就是 blob。然后你会得到blob = result.content; pdf = PDF(); pdf.content = blob
    猜你喜欢
    • 2016-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-14
    相关资源
    最近更新 更多