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 - |
문제
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.
해결책
다른 팁
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)
제휴하지 않습니다 StackOverflow