JQuery File上传400 POST错误请求

时间:2017-02-08 06:44:23

标签: jquery file-upload flask jquery-file-upload blueimp

尝试上传到我的Flask服务器时,我一直遇到砖墙400 POST错误。我理解这可能意味着我的服务器接收的响应不兼容。任何有关如何使这项工作的见解都会很棒。

烧瓶中:

@app.route('/uploads', methods=['GET','POST'])
def uploads():
     if request.method == 'POST':

        files = []
        file = request.files['files[]']
        # if file and allowed_file(file.filename):
        if file:
            print 'its allowed'
            filename = (file.filename)
            file.save(os.path.join(DefaultConfig.UPLOAD_PATH, filename))
            f = {
                'name': filename
            }
            files.append(f)
            return jsonify(files=files)

          #  return jsonify({'status': 'success'}), 201
     pass

JQuery的:

        <script>

    $(document).ready(function($) {
        // Initialize the jQuery File Upload widget
        $('#fileupload').fileupload({
          url: 'https://1d805e8f.ngrok.io/uploads',
            done: function (e, data) {
                $.each(data.result.files, function (index, file) {
                    var message = 'Upload complete: ' + file.name + ' (' +
                        file.size + ' bytes)';
                    $('<p/>').text(message).appendTo(document.body);
                    console.log(message);
                });
            }
        });

        // setup videojs-record
        var player = videojs('myVideo',
        {
            controls: true,
            width: 600,
            height: 300,
            plugins: {

                record: {
                    audio: true,
                    video: true,
                    maxLength: 20,
                    debug: true
                }
            }
        });

        // player error handling
        player.on('deviceError', function()
        {
            console.warn('device error:', player.deviceErrorCode);
        });
        player.on('error', function(error)
        {
            console.log('error:', error);
        });

        // data is available
        player.on('finishRecord', function()
        {
            // the blob object contains the audio data
            var audioFile = player.recordedData;

            console.log('finished recording: ', audioFile);

            // upload data to server
            var filesList = [audioFile];
            $('#fileupload').fileupload('add', {files: filesList});
        });

    });

HTML

    <input id="fileupload" type="file" name="files[]" multiple>

0 个答案:

没有答案