使用Apache中的Flask应用程序上传文件 - 返回Http 400

时间:2018-04-11 14:22:30

标签: python apache flask

我正在使用cgiFlask部署Apache 2.4应用。该应用程序已部署并正常运行,我可以呈现页面并下载报告和其他内容。

但我无法上传任何文件。在我的本地,它工作正常,我可以上传文件。但不是在Apache。 (Apache 2.4安装在Windows Server 2012 R2中)。

它返回Http响应 - 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.

我进行了调试,发现request.files发出错误。 files对象中可能不存在request

if request.method == 'POST':
    if 'file' not in request.files:
        return jsonify({'response' : 1, 'msg' : 'No File part'})

    myfile = request.files['file']

    if myfile.filename == '':
        return jsonify({'response' : 1, 'msg' : 'No File selected'})

    myAllowedFile = myfile.filename.rsplit('.', 1)[1] in ALLOWED_EXTENTIONS

表单的html代码如下 -

<form id='upload_file' method='post' enctype="multipart/form-data">

    <table id='uploadTable'>
        <tr>
            <td><label for='file'>Select a file:</label><input type='file' name='file' id='uploadfile'></td>

            <td><button id='upload-file-button' type='button' name='file'>Upload</button></td>
        </tr>
    </table>

</form>

0 个答案:

没有答案