You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{
"statusCode": 400,
"code": "FST_ERR_CTP_INVALID_CONTENT_LENGTH",
"error": "Bad Request",
"message": "Request body size did not match Content-Length"
}
There seems to be a discrepancy on how the request body size is calculated on the server and the Content-Length header that is automatically calculated by the browser.
What I tried doing to make it work:
By looking around I discovered that if I comment out this code in the api-server package
the fetch will not fail anymore but I couldn't access the request body in the custom function probably because the content parser is not configured properly.
Another interesting thing is that if instead of changing the code in the api-server package I only comment it out and then add
to my api/src/server.ts the fetch will still not work.
Might be something to look into, it would be strange if the addContentTypeParser added in api/src/server.ts would not be applied.
Another option I tried was installing @fastify/multipart and then registering it in my api/src/server.ts as server.register(multipart) but with no success at all.
What's not working?
Uploading files using a custom function and fastify doesn't seem to work.
There was some discussion on the forum https://community.redwoodjs.com/t/uploading-files-using-redwood-function-and-fastify/5814/8 but there was no solution there so I'm opening an issue for it.
The Problem:
I am trying to create a custom function to upload files but it's not working.
I'm calling my custom function like this:
and getting the following response:
There seems to be a discrepancy on how the request body size is calculated on the server and the Content-Length header that is automatically calculated by the browser.
What I tried doing to make it work:
By looking around I discovered that if I comment out this code in the
api-server
packageredwood/packages/api-server/src/plugins/api.ts
Lines 41 to 45 in 605545e
the fetch will not fail anymore but I couldn't access the request body in the custom function probably because the content parser is not configured properly.
Another interesting thing is that if instead of changing the code in the
api-server
package I only comment it out and then addto my
api/src/server.ts
the fetch will still not work.Might be something to look into, it would be strange if the
addContentTypeParser
added inapi/src/server.ts
would not be applied.Another option I tried was installing
@fastify/multipart
and then registering it in myapi/src/server.ts
asserver.register(multipart)
but with no success at all.How do we reproduce the bug?
Create a simple custom function
On the frontend call the function as such and check the network tab to see the error message
What's your environment? (If it applies)
No response
Are you interested in working on this?
The text was updated successfully, but these errors were encountered: