如何处理webapp2中的上传文件 [英] How to handle uploaded files in webapp2

查看:132
本文介绍了如何处理webapp2中的上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google appengine的webapp2有一个非常神秘的有关处理上传文件的文档

 上传的文件可以直接在request.POST中作为cgi.FieldStorage(请参阅cgi模块)实例使用。 

我有一个表单,它使得我想要存储在NDB中的JSON文件发出POST请求。 JSONProperty。

任何人都可以提供一个简短的例子,说明如何从请求对象读取文件吗?

解决方案

您可以在表单中使用 enctype =multipart / form-data,然后在您的处理程序中使用文件内容:

  raw_file = self.request.get('field_name')

然后,将raw_file作为输入传递给模型的属性。


Google appengine's webapp2 has a very cryptic documentation regarding the handling of uploaded files.

Uploaded files are available as cgi.FieldStorage (see the cgi module) instances directly in request.POST.

I have a form which makes a POST request of JSON files which I want to store in an NDB.JsonProperty.

Can anyone offer a short example of how do I read the file from the request object?

解决方案

You can use enctype="multipart/form-data" in your form, and then get file content by using in your handler:

raw_file = self.request.get('field_name')

Then, pass raw_file as input to your model's property.

这篇关于如何处理webapp2中的上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆