App Engine - save response from API to data store as file (blob)

I hit my head against the wall with this:

What I want to do is save the file that is returned from the API to the data store as a blob.

Here is the code I use on my local machine (which, of course, works because of the existing file system):

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

Since I cannot write the file in App Engine, I tried several ways to save the response without success. Any clues on how to do this? I tried to do this with StringIO and was able to save the response, but then could not save it as a blob in the data store.

Thank you, Chris

+3
source share
1 answer

. ().

    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)

"getvalue()", . , - :)

+2

Source: https://habr.com/ru/post/1747679/


All Articles