question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Axios cannot upload a blob, sends an empty body.

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:9

github_iconTop GitHub Comments

4reactions
oliverpoolcommented, Nov 23, 2019

For me this works fine (v0.19.0):

axios.put(url, blob, {
      headers: { "content-type": blob.type }
    });

Maybe you have to replace {data: blob} with blob

(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 😉

0reactions
chinesedfancommented, Feb 26, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found