Axios cannot upload a blob, sends an empty body.
See original GitHub issueI think it may be related to #415…
I’m trying to upload a blob to S3, like so:
await axios.put(
'https://s3.amazonaws.com/.../foo.jpg',
{ data: blob },
{ headers: { 'x-amz-acl': 'public-read', 'Content-Type': 'image/jpeg' },
})
This ends up sending an empty body. Whereas this works easily with fetch:
const stuff = await fetch(
'https://s3.amazonaws.com/.../foo.jpg',
{
method: 'PUT',
body: blob,
headers: {
'Content-Type': 'image/jpeg',
'x-amz-acl': 'public-read',
},
},
)
In #415, it mentions needing to change the content-type to multipart/form-data
, but actually I don’t want to submit a form, I just want to upload the blob to S3.
Am I missing something obvious?
Context
- axios version: v0.15.3
- Environment: Node v8
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:9
Top Results From Across the Web
Send Blob to server with Axios, receiving an empty object
As you are sending the data in multipart , you need to listen to the data event to get the body data. If...
Read more >Handle Blobs requests with Axios the right way - Medium
The tricky part here is that we need to specify that we are sending FormData in the Request Headers. The response will be...
Read more >Can't upload a file from node.js to my route, getting empty ...
I am trying to upload a local file using NodeJs (the file is in the same directory as app.js) to my remote Laravel...
Read more >Send a File With Axios in Node.js - Maxim Orlov
Before uploading a file with axios, you first need to create a form and append the file to it. Axios can be used...
Read more >Multer: Easily upload files with Node.js and Express
The code in the image above means that the req.body object is empty, which is to be expected. If you'll recall, body-parser ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For me this works fine (v0.19.0):
Maybe you have to replace
{data: blob}
withblob
(I know this thread is quite old, but it appears quite high in search engines: I hope that it will save me some time next time 😉
Closed due to old version of axios. And @oliverpool confirmed it works now. https://github.com/axios/axios/issues/1569#issuecomment-557833903.
If other users met similar problems, feel free to open a new issue with the required template.