我有以下代码:
<input type="file" onchange={fileChange} accept="image/*" />
function fileChange({target: { files }}){
const file = files[0]
uploadFile(file)
});
const imgBB = createApi({
baseQuery: fetchBaseQuery({ baseUrl: 'https://api.imgbb.com/1/' }),
endpoints: (builder) => ({
upload: builder.mutation({
query: (file) => ({
url: '/upload?key=MY_API_KEY',
method: 'POST',
body: file,
}),
}),
}),
})
export default imgBB
export const { useUploadMutation } = imgBB
我从服务器收到以下响应:
1条答案
按热度按时间yhqotfr81#
Redux工具包查询并不是真正用来上传文件的,你最好将createAsyncThunk与axios或axios-basequery一起使用。下面是关于这个主题的一个很好的讨论github