반응형
https://stackoverflow.com/questions/76340703/send-form-data-with-rtk-query
send form data with rtk query
I wanna send an image with form data to the nest js server with RTK query but the file didn't send. the code are: uploadImage: builder.mutation<any, any>({ query: (imageFile) => { ...
stackoverflow.com
이걸 보고 시도했지만 에러가 났다. 왤까...
rtk-query 홈페이지에서 formdata를 검색해도 나오는게 없어서 좀 헤맸다.
saveBoard: builder.mutation<boolean, { boardId: any; boardForm: FormData }>({
query: (data) => {
const { boardId, boardForm } = data
return {
url: boardId ? `/${boardId}` : '',
method: boardId ? 'PATCH' : 'POST',
body: boardForm,
formData: true,
}
},
}),
결론: headers 에 content-type:multipart/formdata를 넣을 필요가 없다. formData: true만 설정해도 된다.
728x90
반응형
'Library' 카테고리의 다른 글
[redux-persist] WebStorage에 light/dark mode 저장하기 (0) | 2024.02.19 |
---|---|
[devextreme] when your areaIndex of PivotGrid doesn't work (0) | 2022.10.27 |
react-hook-form data not bounded, useForm not working (0) | 2022.05.13 |
"editor.defaultFormatter": "esbenp.prettier-vscode", value is not accepted (0) | 2022.05.13 |
Tailwind 설정 방법 참고 링크 (0) | 2022.05.10 |