I'm using ajax
to send file via POST
request to the server (my Flask
app), but I can only retrieve this file (binary data) in Flask
using request.form
, not request.files
, and request.files
is desired. Code as below.
How can I get file with request.files
? (Conversely, with Postman
and other tools, I can get the file with request.files
. In request.form
case, info such as content-type
is missing)
// "file_content" is read previously
var formData = new FormData();
formData.append("file", file_content); // "file_content" is binary data
.ajax({
type:"POST",
async: false,
url: ...,
data: formData,
dataType:"json",
processData: false,
contentType: false,
});
The tricky thing is send a local file, and most relevant answers are using document.getElementById().