Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
108
rated 0 times [  111] [ 3]  / answers: 1 / hits: 7639  / 10 Years ago, sun, august 17, 2014, 12:00:00

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

More From » flask

 Answers
13

Check request.files for the file.



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

[#43077] Friday, August 15, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
keric

Total Points: 572
Total Questions: 93
Total Answers: 97

Location: Cyprus
Member since Mon, Oct 24, 2022
2 Years ago
;