最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why is Flask not receiving my POST Blob? - Stack Overflow

programmeradmin3浏览0评论

My problem is that I'm sending a Blob to the server with FormData, but the server isn't getting it. Code looks like the following:

Flask server code:

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

Client JS Code:

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);
    });

My problem is that I'm sending a Blob to the server with FormData, but the server isn't getting it. Code looks like the following:

Flask server code:

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

Client JS Code:

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);
    });
Share Improve this question asked Aug 17, 2014 at 0:07 user592419user592419 5,23310 gold badges46 silver badges69 bronze badges 3
  • No. Everything to do with the form I make above. Is enctype necessary? – user592419 Commented Aug 17, 2014 at 0:16
  • The blob, btw, is a sound blob from recorder.js – user592419 Commented Aug 17, 2014 at 0:17
  • are you sure? the answer here, stackoverflow./questions/5392344/…, suggests that that's not the way to go. And replacing the 'contentType:false' with 'contentType:multipart/form-data' didn't fix it. Do you mean something else? – user592419 Commented Aug 17, 2014 at 0:24
Add a ment  | 

1 Answer 1

Reset to default 6

Check request.files for the file.

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

评论列表(0)

  1. 暂无评论