Issue with Server Actions sending post request
Unanswered
Scarlet Tanager posted this in #help-forum
Scarlet TanagerOP
I want to send a post request to API through server actions at client component and the data payload are going as JSON not as FormData how to fix that
4 Replies
Uhhh this isn’t really an issue with the use server directive. As all that does it tell react to generate an api endpoint so don’t think of it like that.
multipart/form-data
multipart/form-data
I’m on my phone so sorry for formatting…
fetch(url, {
method: ‘POST’
headers: {
'Accept': 'application/json, application/xml, text/plain, text/html, .',
'Content-Type': 'multipart/form-data'
},
body: JSON.stringify(data) || null,
}).
fetch(url, {
method: ‘POST’
headers: {
'Accept': 'application/json, application/xml, text/plain, text/html, .',
'Content-Type': 'multipart/form-data'
},
body: JSON.stringify(data) || null,
}).
I believe it would be something like this.
@riský can you do me a favor if your around and format that in a code snippet 😂😂😂 it’s being difficult on my iPhone lol