Passing file from client to server action
Unanswered
Polar bear posted this in #help-forum
Polar bearOP
I want to pass a file from an input from the client to a server action to upload it. In the end I want to upload the Uint8Array of the file. I can't pass the File directly, so can I pass it any other way?
3 Replies
@Polar bear I want to pass a file from an input from the client to a server action to upload it. In the end I want to upload the Uint8Array of the file. I can't pass the File directly, so can I pass it any other way?
Turkish Van
I might be wrong, but You should always be able to pass it as an element of FormData.
Here You can check React docs for a list of serializable arguments and values:
https://react.dev/reference/rsc/use-server#serializable-parameters-and-return-values
Here You can check React docs for a list of serializable arguments and values:
https://react.dev/reference/rsc/use-server#serializable-parameters-and-return-values
Polar bearOP
I'm not using a server action directly though, I first use onSubmit, and then I want to use a server action to upload the image, not submit the whole form. Sorry if I explained it vague, and sorry that my code's so weird :)
there are only a few valid types you can send and formdata is the best one for file i am pretty sure (you could base64 or send the array as list, but i think just making formdata and adding file is fine)