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
1 Answer
Reset to default 6Check request.files
for the file.
@app.route('/save-record', methods=['POST'])
def save_record():
app.logger.debug(request.files['file'].filename)