sanjar-notes / frontend

The basics - HTML, CSS, Javascript, browser APIs, performance
3 stars 0 forks source link

Spreading file upload (multipart) payload in axios doesn't work #108

Open sanjarcode opened 10 months ago

sanjarcode commented 10 months ago
const id, params, payload;
axios.put(`/vendors/${id}`, { ...payload, id }, { params }); // won't work
axios.put(`/vendors/${id}`, payload, { params: { ...params, id } }); // works, of course BE is RoR so values can be passed in body or query param

Find a fix.

sanjarcode commented 10 months ago

Not an axios issue. Payload should either be string (JSON.stringify) or FormData, can't be a mix. Axios accepts objects, but again, if FormData is involved, make sure it's passed as is as second param