首页 > javascript > Python,Flask - 如何使用DHTML上传器加载文件

Python,Flask - 如何使用DHTML上传器加载文件 (Python, Flask - How to Use DHTML uploader to load a file)

问题

我正在使用dhtmlx上传程序上传文件。

这是我的JS代码

{type: "label",label: ""},
{type: "upload",name: "creatives",inputWidth: 330,
 url: "/upload_creative",
_swfLogs: "enabled",
 swfPath: "static/js/dhtmlxForm/codebase/ext/uploader.swf",
 swfUrl: "/upload_creative"
},  

这是我将接收文件的python代码。

@app.route('/upload_creative', methods=["GET", "POST"])
@login_required
def upload_creative():
    if request.method == "POST":
        print 'request.form', request.form

所以...从python ....如何获取文件的名称,以便我可以保存到磁盘?我期待图像文件。

当我上传时,我会在日志中看到这一点。

request.form ImmutableMultiDict([])
127.0.0.1 - - [15/Sep/2012 23:59:56] "POST /upload_creative?mode=html5&1347724796791 HTTP/1.1" 200 -

解决方法

from flask import request
...

imgfile = request.files['file-id']
imgname = imgfile.filename

问题

I am using dhtmlx uploader to upload files.

Here is my JS code

{type: "label",label: ""},
{type: "upload",name: "creatives",inputWidth: 330,
 url: "/upload_creative",
_swfLogs: "enabled",
 swfPath: "static/js/dhtmlxForm/codebase/ext/uploader.swf",
 swfUrl: "/upload_creative"
},  

Here is my python code that will receive the files.

@app.route('/upload_creative', methods=["GET", "POST"])
@login_required
def upload_creative():
    if request.method == "POST":
        print 'request.form', request.form

So...from python....how do I get the name of the file so I can save to disk? I am expecting image files.

When I upload I see this in the logs.

request.form ImmutableMultiDict([])
127.0.0.1 - - [15/Sep/2012 23:59:56] "POST /upload_creative?mode=html5&1347724796791 HTTP/1.1" 200 -

解决方法

from flask import request
...

imgfile = request.files['file-id']
imgname = imgfile.filename
相似信息