在webapp2 / GAE中上传文件 [英] Uploading Files in webapp2/GAE
问题描述
我需要基于Webapp2(Python)从Google App Engine应用程序的表单上载和处理CSV文件。我知道我可以使用blobstore临时存储文件,但我很想知道是否有办法处理文件而不必存储它。 上传文件的内容位于 self .request.POST
在你的处理程序中,所以你可以得到这些内容(假设例如上传文件的字段被命名为'foo'
)例如
content = self.request.POST.multi ['foo']。file.read()
现在您将内容作为字符串处理 - 按照您的意愿进行处理。这当然假定将放在内存中(没有多兆字节的上传!)...
...I need to upload and process a CSV file from a form in a Google App Engine application based on Webapp2 (Python) I understand I could use blobstore to temporary store the file but I am curious to know if there is a way to process the file without having to store it at all.
The content of uploaded files is in self.request.POST
in your handler, so you can get that content (assuming e.g the field for the uploaded file is named 'foo'
) with e.g
content = self.request.POST.multi['foo'].file.read()
So now you have the content as a string -- process it as you wish. This does of course assume the thing will fit in memory (no multi-megabyte uploads!-)...
这篇关于在webapp2 / GAE中上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!