[英]How to obtain a file object from a variable or from http URL without actually creating a file?
I want to manipulate a downloaded PDF using PyPDF and for that, I need a file object. 我想使用PyPDF处理下载的PDF,为此,我需要一个文件对象。
I use GAE to host my Python app, so I cannot actually write the file to disk. 我使用GAE托管我的Python应用程序,因此实际上无法将文件写入磁盘。
Is there any way to obtain the file object from URL or from a variable that contains the file contents? 有什么方法可以从URL或包含文件内容的变量中获取文件对象?
TIA. TIA。
大多数工具(包括urllib
)已经为您提供了类似文件的功能,但是如果您需要真正的随机访问,则需要创建一个StringIO.StringIO
并将数据读入其中。
In GAE you can use the blobstore to read, write file data and to upload and download files. 在GAE中,您可以使用Blobstore读取,写入文件数据以及上传和下载文件。 And you can use the File API:
您可以使用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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.