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.
How to obtain a file object from a variable or from http URL without actually creating a file?
-
10-12-2021 - |
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.
Solution
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