Hamid
Hamid

Reputation: 73

Can't access any method of formData object in React Native, except append

I'm trying to run the following code in react native(Expo):

import FormData from "form-data"; // installed with npm install 'form-data'

const formData = new FormData();

console.log(formData.getHeaders());    <------- formData.getHeaders is not a function. (In 'formData.getHeaders()', 'formData.getHeaders' is undefined)

But the only method that works is append.

getHeaders() works if I run the above code with node, but doesn't work in react native app.

Why doesn't it recognize the FormData methods such as getHeaders() or getBoundary()?

Upvotes: 0

Views: 1035

Answers (2)

Hamid
Hamid

Reputation: 73

It was due to a bug in axios version 0.25.0 https://github.com/axios/axios/issues/4406. It's now fixed.

Upvotes: 1

Mohammed naji
Mohammed naji

Reputation: 1102

all you need is to replace the import line with this

import * as FormData from "form-data";

const formData = new FormData();


console.log(formData.getHeaders());    

Upvotes: 1

Related Questions