简体   繁体   English

App Engine - 将数据存储中API的响应保存为文件(blob)

[英]App Engine - Save response from an API in the data store as file (blob)

I'm banging my head against the wall with this one: 我用这个撞在墙上撞到了我的头:

What I want to do is store a file that is returned from an API in the data store as a blob. 我想要做的是将从数据存储中的API返回的文件存储为blob。

Here is the code that I use on my local machine (which of course works due to an existing file system): 这是我在本地机器上使用的代码(当然由于现有的文件系统而起作用):

client.convertHtml(html, open('html.pdf', 'wb'))

Since I cannot write to a file on App Engine I tried several ways to store the response, without success. 由于我无法写入App Engine上的文件,我尝试了几种方法来存储响应,但没有成功。 Any hints on how to do this? 关于如何做到这一点的任何提示? I was trying to do it with StringIO and managed to store the response but then weren't able to store it as a blob in the data store. 我试图用StringIO来做,并设法存储响应,但后来无法将其存储为数据存储中的blob。

Thanks, Chris 谢谢,克里斯

Found the error. 发现错误。 Here is how it looks like right now (simplified). 以下是它现在的样子(简化)。

    output = StringIO.StringIO()

    try:
        client.convertURI("example.com", output)
        Report.pdf = db.Blob(output.getvalue())
        Report.put()  
    except pdfcrowd.Error, why:
        logging.error('PDF creation failed %s' % why)

I was trying to save the output without calling "getvalue()", that was the problem. 我试图保存输出而不调用“getvalue()”,这就是问题所在。 Perhaps this is of use to someone in the future :) 也许这对未来的某个人有用:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM