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

use*_*419 5 javascript blob form-data flask

我的问题是我使用 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
Run Code Online (Sandbox Code Playgroud)

客户端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);
    });
Run Code Online (Sandbox Code Playgroud)

Mus*_*usa 6

检查request.files文件。

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