'Why the FormData is blank in react native
Why when I do a console.log(), just after the last form.append("","") work well I see what I push in them, and than when I watch on the backend is blanked ?
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the clientthis error occured when I adding"Content-Type": "multipart/form-data"on the headers , do you know what happended ???
const uri = pictureUri.uri;
const uriParts = uri.split(".");
const fileType = uriParts[1];
const form = new FormData();
form.append("categorie","someCategorieInthere");
form.append("picture", {
uri,
name: `picture.${fileType}`,
type: `image/${fileType}`,
});
const handlSubmit = async () => {
try {
await axios.put("blablbla_url",
form,
{
headers: {
Authorization: `Bearer ${token}`,
Accept: "application/json",
"Content-Type": "multipart/form-data",
},
}
);
} catch (error) {
console.log({ message: error });
}
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
