File added to server action request for no reason
Answered
Cape horse mackerel posted this in #help-forum
Cape horse mackerelOP
1. Create a FormData object, add a file to it and POST to an API route.
2. Call Server Action with parameters that are unrelated to that formdata object or file itself. The Action in question has nothing to do with files or formdata or anything.
3. I get a request too large error when calling the Action, and inspecting the request shows the file being added to the request.
Please help 😃
2. Call Server Action with parameters that are unrelated to that formdata object or file itself. The Action in question has nothing to do with files or formdata or anything.
3. I get a request too large error when calling the Action, and inspecting the request shows the file being added to the request.
Please help 😃
Answered by Cape horse mackerel
I've tried to replicate it and in doing so, I think the file is getting sneaked into one of the action parameters (damn you nested objects).
So this is really a user error.
Sorry to have wasted your time and thank you for helping!
So this is really a user error.
Sorry to have wasted your time and thank you for helping!
11 Replies
@Cape horse mackerel 1. Create a FormData object, add a file to it and POST to an API route.
2. Call Server Action with parameters that are unrelated to that formdata object or file itself. The Action in question has nothing to do with files or formdata or anything.
3. I get a request too large error when calling the Action, and inspecting the request shows the file being added to the request.
Please help 😃
What exactly do you need help with? You can increase size Limit if you want
Cape horse mackerelOP
You may have misunderstood the issue. The file shouldn't be in the Server Action request at all.
The Server Action is being called after the file is uploaded to the server. The action is for something unrelated to the file, and uses unrelated parameters. The file has no reason to be in the request.
Wait, so you’re just posting it to an api route, and when you run a server action, the file is also magically present there
Cape horse mackerelOP
That's correct
Cape horse mackerelOP
When I submit the form, it goes through each field and calls a client-side validation method for that field.
It iterates through again and calls a client-side mutation method for that field. For an image field, that uploads the file using an API route and returns the key.
I iterate through the mutated fields and call server-side validation methods for each field.
That's where the error appears. The field it tries to validate is not even the image field, just a text field.
It iterates through again and calls a client-side mutation method for that field. For an image field, that uploads the file using an API route and returns the key.
I iterate through the mutated fields and call server-side validation methods for each field.
That's where the error appears. The field it tries to validate is not even the image field, just a text field.
Cape horse mackerelOP
Also side note: changing the body size limit doesn't seem to work in production.
@Cape horse mackerel That's correct
Can you provide a min repro repo?
Cape horse mackerelOP
Ah I was hoping there was a simple gotcha that I overlooked because of how weird it is.
I'll try and replicate it shortly. Thanks!
I'll try and replicate it shortly. Thanks!
Ping me once you give a min repro repo
Cape horse mackerelOP
I've tried to replicate it and in doing so, I think the file is getting sneaked into one of the action parameters (damn you nested objects).
So this is really a user error.
Sorry to have wasted your time and thank you for helping!
So this is really a user error.
Sorry to have wasted your time and thank you for helping!
Answer