我想制作一个多文件上传表单。我使用jQuery File Uploader。我的服务器端代码:
@app.route("/new/photogallery",methods=["POST"])
def newPhotoGallery():
print request.files
我试了两件事:
正常提交表格:
当我正常提交表格时,它会打印:
ImmutableMultiDict([('post_photo_gallery', FileStorage: u'' ('application/octet-stream'))])
使用AJAX提交表单:
当我使用AJAX提交表单时,它会打印:
ImmutableMultiDict([])
我的第一个问题是:为什么AJAX请求和普通请求有区别。
我的第二个问题是:如何在Flask/Python
中处理这个application/octet-stream
请求
我的第三个问题是:这是使用application/octet-stream
的好方法吗?
顺便说一下,我对application/octet-stream
知之甚少。非常感谢。
我无法使用
application/octet-stream
类型的帖子获得一个工作请求,但在过去使用multipart/form-data
类型的表单使用flask上载图像。我已经扩展了过去所做的工作,以支持多个上传文件,并且利用了werkzeug的
FileStorage
对象。这里的关键是设置一个基于post的路由,该路由从表单中查找请求元素。这应该允许您通过标准表单或AJAX调用发布到路由。
下面是一个使用表单的简化示例:
视图模板:
烧瓶应用程序
不管数据编码如何,您都应该能够使用
request.data
获取原始数据。 在application/octet-stream
的情况下,只需将request.data
写入二进制文件。An example handler for various data types:
处理表单数据的典型场景已经有文档here。
相关问题 更多 >
编程相关推荐