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

6
我是一名能够提供翻译的有用助手。
我的问题是我正在使用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);
    });

不,这与我上面制作的表单有关。enctype是必需的吗? - user592419
这个“blob”,顺便说一下,是来自于Recorder.js的一个声音数据块。 - user592419
1个回答

6

查看request.files以获取文件。

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接