N
Nuxt4mo ago
munte8065

FormData in Nuxt

Hello friends, I need to use FormData for a POST api call. Here is my FormData const formData = new FormData(); formData.append("your-name", "someEmail"); formData.append("your-company-name", "someEmail"); formData.append("your-email", "[email protected]"); My first implement is with useFetch const { data, error } = await useFetch( runtimeConfig.public.CONTACT_FORM_API, { method: "POST", headers: { "Content-Type": multipart/form-data; charset=utf-8; boundary= + ${Math.random().toString()}, Accept: "/", }, body: formData, } ); Sadly , it does not work because when I check on back-end, the data is empty. My second implement is with useFetch useAsyncData and $fetch const { data } = await useAsyncData("contactForm", () => $fetch(runtimeConfig.public.CONTACT_FORM_API, { method: "POST", headers: { "Content-Type": multipart/form-data; charset=utf-8; boundary= + ${Math.random().toString()}, Accept: "/", }, body: formData , }) ); it still does not work as on back-end, the data is empty. So I think that i did not attach FormData correctly. I search about it on google, gemini, chatGPT, claude, blackbox, but it was no use. Can somebody help me please ?? Thank you so much in advance.
1 Reply
munte8065
munte8065OP4mo ago
I solved it. I removed Content-type header. Have a great day guys
Want results from more Discord servers?
Add your server