javascript/python/flask - formData not sending uploaded file to server [duplicate]
This question already has an answer here:
How to get data received in Flask request
15 answers
I'm trying to send a user uploaded file to my server through an axios
POST request with formData
and it is not working.
What doesn't work:
const formData = new FormData();
formData.append('batch', batch);
formData.append('file', files[i]);
console.log(formData.get('batch')); // outputs 894489 correctly
console.log(formData.get('file')); // outputs fileObject correctly
axios.post('/api/upload', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
});
response from python
print(request.form)
# ImmutableMultiDict([('batch', '894489')])
# Why is the file missing?
What does work:
const formData = new FormData();
formData.append('batch', batch);
formData.append('file', 'test');
console.log(formData.get('batch')); // outputs 894489 correctly
console.log(formData.get('file')); // outputs 'test' correctly
axios.post('/api/upload', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
});
response from python
print(request.form)
# ImmutableMultiDict([('batch', '894489'), ('file', 'test')])
# Why is the file appearing?
My files[i]
is a valid file and is being recognized in JS. This is confirmed with the console.log(formData.get('file'));
which always outputs the correct file.
Somewhere along the way the file is lost and unavailable to python yet strangely if I append a string instead, it works. Any ideas?
javascript python flask multipartform-data
marked as duplicate by davidism
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 26 '18 at 1:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How to get data received in Flask request
15 answers
I'm trying to send a user uploaded file to my server through an axios
POST request with formData
and it is not working.
What doesn't work:
const formData = new FormData();
formData.append('batch', batch);
formData.append('file', files[i]);
console.log(formData.get('batch')); // outputs 894489 correctly
console.log(formData.get('file')); // outputs fileObject correctly
axios.post('/api/upload', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
});
response from python
print(request.form)
# ImmutableMultiDict([('batch', '894489')])
# Why is the file missing?
What does work:
const formData = new FormData();
formData.append('batch', batch);
formData.append('file', 'test');
console.log(formData.get('batch')); // outputs 894489 correctly
console.log(formData.get('file')); // outputs 'test' correctly
axios.post('/api/upload', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
});
response from python
print(request.form)
# ImmutableMultiDict([('batch', '894489'), ('file', 'test')])
# Why is the file appearing?
My files[i]
is a valid file and is being recognized in JS. This is confirmed with the console.log(formData.get('file'));
which always outputs the correct file.
Somewhere along the way the file is lost and unavailable to python yet strangely if I append a string instead, it works. Any ideas?
javascript python flask multipartform-data
marked as duplicate by davidism
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 26 '18 at 1:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How to get data received in Flask request
15 answers
I'm trying to send a user uploaded file to my server through an axios
POST request with formData
and it is not working.
What doesn't work:
const formData = new FormData();
formData.append('batch', batch);
formData.append('file', files[i]);
console.log(formData.get('batch')); // outputs 894489 correctly
console.log(formData.get('file')); // outputs fileObject correctly
axios.post('/api/upload', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
});
response from python
print(request.form)
# ImmutableMultiDict([('batch', '894489')])
# Why is the file missing?
What does work:
const formData = new FormData();
formData.append('batch', batch);
formData.append('file', 'test');
console.log(formData.get('batch')); // outputs 894489 correctly
console.log(formData.get('file')); // outputs 'test' correctly
axios.post('/api/upload', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
});
response from python
print(request.form)
# ImmutableMultiDict([('batch', '894489'), ('file', 'test')])
# Why is the file appearing?
My files[i]
is a valid file and is being recognized in JS. This is confirmed with the console.log(formData.get('file'));
which always outputs the correct file.
Somewhere along the way the file is lost and unavailable to python yet strangely if I append a string instead, it works. Any ideas?
javascript python flask multipartform-data
This question already has an answer here:
How to get data received in Flask request
15 answers
I'm trying to send a user uploaded file to my server through an axios
POST request with formData
and it is not working.
What doesn't work:
const formData = new FormData();
formData.append('batch', batch);
formData.append('file', files[i]);
console.log(formData.get('batch')); // outputs 894489 correctly
console.log(formData.get('file')); // outputs fileObject correctly
axios.post('/api/upload', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
});
response from python
print(request.form)
# ImmutableMultiDict([('batch', '894489')])
# Why is the file missing?
What does work:
const formData = new FormData();
formData.append('batch', batch);
formData.append('file', 'test');
console.log(formData.get('batch')); // outputs 894489 correctly
console.log(formData.get('file')); // outputs 'test' correctly
axios.post('/api/upload', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
});
response from python
print(request.form)
# ImmutableMultiDict([('batch', '894489'), ('file', 'test')])
# Why is the file appearing?
My files[i]
is a valid file and is being recognized in JS. This is confirmed with the console.log(formData.get('file'));
which always outputs the correct file.
Somewhere along the way the file is lost and unavailable to python yet strangely if I append a string instead, it works. Any ideas?
This question already has an answer here:
How to get data received in Flask request
15 answers
javascript python flask multipartform-data
javascript python flask multipartform-data
asked Nov 25 '18 at 23:16
dariuscosdendariuscosden
8018
8018
marked as duplicate by davidism
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 26 '18 at 1:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by davidism
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 26 '18 at 1:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
From inside Flask, the files should be accessible using this:
request.files['file']
Thanks man. How did I not see it...
– dariuscosden
Nov 25 '18 at 23:35
1
Not your fault. I have to say sometimes I also get caught in some things when trying to make my front-end talk to flask. I always have to google it
– Pedro Torres
Nov 25 '18 at 23:40
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
From inside Flask, the files should be accessible using this:
request.files['file']
Thanks man. How did I not see it...
– dariuscosden
Nov 25 '18 at 23:35
1
Not your fault. I have to say sometimes I also get caught in some things when trying to make my front-end talk to flask. I always have to google it
– Pedro Torres
Nov 25 '18 at 23:40
add a comment |
From inside Flask, the files should be accessible using this:
request.files['file']
Thanks man. How did I not see it...
– dariuscosden
Nov 25 '18 at 23:35
1
Not your fault. I have to say sometimes I also get caught in some things when trying to make my front-end talk to flask. I always have to google it
– Pedro Torres
Nov 25 '18 at 23:40
add a comment |
From inside Flask, the files should be accessible using this:
request.files['file']
From inside Flask, the files should be accessible using this:
request.files['file']
answered Nov 25 '18 at 23:32
Pedro TorresPedro Torres
683413
683413
Thanks man. How did I not see it...
– dariuscosden
Nov 25 '18 at 23:35
1
Not your fault. I have to say sometimes I also get caught in some things when trying to make my front-end talk to flask. I always have to google it
– Pedro Torres
Nov 25 '18 at 23:40
add a comment |
Thanks man. How did I not see it...
– dariuscosden
Nov 25 '18 at 23:35
1
Not your fault. I have to say sometimes I also get caught in some things when trying to make my front-end talk to flask. I always have to google it
– Pedro Torres
Nov 25 '18 at 23:40
Thanks man. How did I not see it...
– dariuscosden
Nov 25 '18 at 23:35
Thanks man. How did I not see it...
– dariuscosden
Nov 25 '18 at 23:35
1
1
Not your fault. I have to say sometimes I also get caught in some things when trying to make my front-end talk to flask. I always have to google it
– Pedro Torres
Nov 25 '18 at 23:40
Not your fault. I have to say sometimes I also get caught in some things when trying to make my front-end talk to flask. I always have to google it
– Pedro Torres
Nov 25 '18 at 23:40
add a comment |