为什么Flask没有收到我的POST Blob?

时间:2014-08-17 00:07:44

标签: javascript flask blob form-data

我的问题是我正在使用FormData向服务器发送Blob,但是服务器没有得到它。代码如下所示:

Flask服务器代码:

@app.route('/save-record', methods=['POST'])
def save_record():
    app.logger.debug(request.form.keys()) #Shows only the title key, not the file key

客户端JS代码:

var save = function() {
    var form = new FormData();
    form.append('file', record.blob, record.filename);
    form.append('title', searchedObj.title);
    //Chrome inspector shows that the post data includes a file and a title.                                                                                                                                           
    $.ajax({
      type: 'POST',
      url: '/save-record',
      data: form,
      cache: false,
      processData: false,
      contentType: false
    }).done(function(data) {
      console.log(data);
    });

1 个答案:

答案 0 :(得分:2)

检查request.files文件。

@app.route('/save-record', methods=['POST'])
def save_record():
    app.logger.debug(request.files['file'].filename)