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.

Cannot upload file within FormData

See original GitHub issue

Describe the bug

After upgrading from 0.24.0 to 0.25.0 File Form upload breaks.

To Reproduce

Original working on 0.24.0 code.

axios({
    method: "post",
    url: [serverUrl],
    data: formData, // FormData object instance with uploading file field
    timeout: 120000
});

This code was working previously, but now backend cannot extract file field. After specifying content type:

axios({
    method: "post",
    url: [serverUrl],
    data: formData, // FormData object instance with uploading file field
    timeout: 120000,
    headers: {"Content-Type": "multipart/form-data"},
});

I got an error on backend “bad content-type header, no multipart boundary”

Expected behavior

Seems like previous version of axios (0.24.0) automatically add correct header and also boundary. Or was there any breaking change that I didn’t notice?

Environment

  • Axios Version [0.25.0]
  • Node.js Version [16.0.0]
  • Additional Library Versions [formidable 2.0.1, React-Native 0.66.4]

Additional context/Screenshots

Not needed.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:20
  • Comments:27 (3 by maintainers)

github_iconTop GitHub Comments

21reactions
Romick2005commented, Jan 21, 2022

Seems like there is a problem in isFormData function: image

I am using axios in react-native project where:

const form = new FormData();
toString.call(form) === '[object Object]'; // true for React-Native
toString.call(form) === '[object FormData]'; // true for Browser
(form instanceof FormData) // true for both platforms
11reactions
tapzcommented, Jan 31, 2022

Why are these kind of useless “optimizations” even done? Why change something that works? Nobody will see any speed improvement.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with uploading file through form-data axios
here my code to upload file in node.js, it works ok. const form = new FormData(); const file = fse.createReadStream(option.
Read more >
I cannot upload file via HTTP Action with form-data type.
The API from other services can only upload files with form-data type. I try to use form-data type on HTTP action but it...
Read more >
Send a File With Axios in Node.js - Maxim Orlov
Construct a form with form-data library. Before uploading a file with axios, you first need to create a form and append the file...
Read more >
Using FormData Objects - Web APIs | MDN
The FormData object lets you compile a set of key/value pairs to send using XMLHttpRequest. It is primarily intended for use in sending...
Read more >
Question: How to upload a file using HTTP POST Form-Data?
I want to upload a file using HTTP POST where username and password are to be filled using form-data. It works well from...
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