0

I was previously using ApiSauce to post listings from React Native App to Node.js with Multer, and now I have migrated to Axios everything went fine except for the uploading images part.

export const add = (listing, onUploadProgress) => {
const data = new FormData();
data.append('title', listing.title);
data.append('price', listing.price);
data.append('categoryId', listing.category.value);
data.append('description', listing.description);

data.append('userId', listing.userId);

listing.images.forEach((image, index) =>
    data.append('images', {
        name: 'image' + index,
        type: 'image/jpeg',
        uri: image,
    }),
);

if (listing.location)
    data.append('location', JSON.stringify(listing.location));

return client.post(endpoint, data, {
    onUploadProgress: (progress) =>
        onUploadProgress(progress.loaded / progress.total),
        
});
};

1 Answers1

0

you can try to remove all content type. for multipart boundary error

try like this rest is handled by multer

axios.post(`${subURL}/upload-avatar`, formData, { headers: { "Authorization": jwt } })
        .then(response => {
            return response.data
        })
        .catch(err => {
            throw err
        })
sonu sharma
  • 39
  • 1
  • 3