Question

I want to manipulate a downloaded PDF using PyPDF and for that, I need a file object.

I use GAE to host my Python app, so I cannot actually write the file to disk.

Is there any way to obtain the file object from URL or from a variable that contains the file contents?

TIA.

Was it helpful?

Solution

Most tools (including urllib) already give you a file-like, but if you need true random access then you'll need to create a StringIO.StringIO and read the data into it.

OTHER TIPS

In GAE you can use the blobstore to read, write file data and to upload and download files. And you can use the File API:

Example :

_file = files.blobstore.create(mime_type=mimetype, _blobinfo_uploaded_filename='test')
with files.open(_file, 'a') as f :                                                      
    f.write(somedata)                                                         
files.finalize(_file)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top