fetchCarouselData: async (params) => {
let bodyFormData = new FormData();
for (let prop in params) {
bodyFormData.append(prop, params[prop]);
}
return axios({
method: "post",
url: `${baseURL}/fetchCarouselData`,
data: bodyFormData,
headers: { "Content-Type": `multipart/form-data` },
});
};
When making the API call using Axios in Next.js.
If I use "Content-Type":
multipart/form-data;
, I encounter a 'content-type missing boundary' error.Using "Content-Type":
results in a bodyFormData.getBoundary is not a function error.multipart/form-data; boundary=${bodyFormData.getBoundary()};
3) If I don't specify the content type at all ("header:{}") or omit the header parameter, I receive an "unsupported content-type" error.
How can this issue be resolved? Despite the errors, both methods still return a response from the API.
https://i.sstatic.net/OZiCr.png
https://i.sstatic.net/MLwxU.png
However, when testing in Postman, the result is obtained without any errors. https://i.sstatic.net/Borb7.png