6

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);
    });
user592419
  • 5,103
  • 9
  • 42
  • 67
  • No. Everything to do with the form I make above. Is enctype necessary? – user592419 Aug 17 '14 at 00:16
  • The blob, btw, is a sound blob from recorder.js – user592419 Aug 17 '14 at 00:17
  • are you sure? the answer here, http://stackoverflow.com/questions/5392344/sending-multipart-formdata-with-jquery-ajax?rq=1, 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 Aug 17 '14 at 00:24

1 Answers1

6

Check request.files for the file.

@app.route('/save-record', methods=['POST'])
def save_record():
    app.logger.debug(request.files['file'].filename) 
Musa
  • 96,336
  • 17
  • 118
  • 137