XHR/Axios Progress with Server Actions
Hello,
I'm looking into a way to use the NextJS 15 Server Actions to upload files to an S3 bucket (which I have implemented and is working); however I am now trying to get the progress of the file upload and use that in a progress bar.
I have tried looking into XHR and Axios but have only been able to find the solution for API routes and not Server Actions.
My Current Code:
Solution:Jump to solution
I have figured a possible solution? However, I'm unsure if it makes sense to do so or just seems redundant?
But I have created an API route to effectively collect the data; then send it to a controller to separate the
formData
and create different variables for the files and the payload; then I pass that controller data down to the server action.
This does seem to be working....2 Replies
and my upload file is currently looking like this:
I have also tried to add this to the
async function handleOnSubmit(e: any)
function
This will upload the content through the Server Action but won't run the rest of the operation such as onUploadProgress
or the completed .then
. It returns the response error
of POST https://DEVSERVER/PAGE/[object%20Promise] 404 (Not Found)
.Solution
I have figured a possible solution? However, I'm unsure if it makes sense to do so or just seems redundant?
But I have created an API route to effectively collect the data; then send it to a controller to separate the
formData
and create different variables for the files and the payload; then I pass that controller data down to the server action.
This does seem to be working.
The API route looks something like this:
The controller looks something like this:
I then reconfigured my server action to take in the Files: File[]
instead of the formData: FormData
, along with some other general changes.