RTK formData PUT not working
See original GitHub issueI have this file input
<input
type="file"
id="desktop-user-photo"
name="user-photo"
className="absolute inset-0 w-full h-full opacity-0 cursor-pointer border-gray-300 rounded-xs"
onChange={(e) => updatePicture(e.target.files ? e.target.files[0] : null)}
/>
that calls this method:
const [editPicture] = useEditPictureMutation();
const updatePicture = async (file: File | null) => {
const formData = new FormData();
formData.append('file', file);
await editPicture({ formData }).unwrap();
}
here the API slice
editPicture: builder.mutation<Profile, { formData: FormData }>({
query: ({ formData }) => ({
url: `/picture`,
method: 'PUT',
body: formData,
}),
invalidatesTags: [PROFILE_TAG],
}),
When I’m calling this endpoint I have and error from BE: [Nest] Unexpected end of multipart data


If I try to use the same endpoint with swagger it works
I’m using “@reduxjs/toolkit”: “1.8.1”
Any ideas? Thank you in advance!
Issue Analytics
- State:
- Created a year ago
- Comments:14 (4 by maintainers)
Top Results From Across the Web
"Multipart/form-data" is not woking in React-redux ...
When I am sending data from postman form-data it is working fine but through frontend I am not getting that unexpected result.
Read more >React + RTK Query + Material UI: Image Upload 2022
In this article, you'll learn how to upload images with React, RTK Query, Redux Toolkit, Zod, React Hook Form and Material UI.
Read more >API call with multipart form-data not working : r/PowerShell
Hi all. I've attempted everything I could find online to convert this javascript to powershell and have been unsuccessful. 9/10 times I get...
Read more >Redux Essentials, Part 8: RTK Query Advanced Patterns
RTK Query allows multiple components to subscribe to the same data, and will ensure that each unique set of data is only fetched...
Read more >How to Multipart File Upload Using FormData with React ...
Use-cases include, but are not limited to admin panels, B2B applications and dashboards. Headless : Works with any UI framework. ⚙️ Zero- ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We don’t set headers when the body is
FormData
and file uploads should just work (I do this myself with RTKQ in many projects). You can see by the screenshots that it’s generating the form boundary and such as expected. This is most likely an API issue.Reference: https://github.com/reduxjs/redux-toolkit/blob/master/packages/toolkit/src/query/tests/fetchBaseQuery.test.tsx#L675-L694
@fs-innonova It is indeed an issue with fetch. You can use axios instead of baseQuery.
https://redux-toolkit.js.org/rtk-query/usage/customizing-queries#axios-basequery.
I used modified version of this example and got it to work.