Search code examples
javascriptpythonflaskdhtmlx

Python, Flask - How to Use DHTML uploader to load a file


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 -

Solution

  • from flask import request
    ...
    
    imgfile = request.files['file-id']
    imgname = imgfile.filename