I have here a problem with multiple images. My problem is that I want to upload multiples image through an API. The API can't handle it through one request. That's why I wanted to upload images one by one and call the API one by one. How do i do it?
export const saveImages =
({ images = [], oldImages, isNew }) =>
async (dispatch) => {
try {
dispatch({
type: constants.REQUEST,
});
let responses;
if (images?.length) {
let formData = new FormData();
const requests = images.map(({ imageFileName, imageFile }) => {
formData.append(imageFileName, imageFile);
formData.append("isNewProduct", isNew);
return axios.post(
`${URL}/saveImages`,
formData
);
});
responses = await Promise.all(requests);
}
dispatch({
type: constants.SUCCESS,
payload: [...(oldImages || []), ...response?.data],
});
} catch (error) {
dispatch({
type: constants.FAILURE,
});
}
};
axioslibraryimagesarray and make individual network requests? What is the point of having a"/bulk-upload-image"endpoint if you can't bulk upload to it? Do you have a different endpoint to use for single individual uploads? What have you tried already?response = await axios.post(`${URL}/bulk-upload-image`, formData);not process them all at once and give you success? If you really need to split them up into individual requests then map the images to an array of Promises (axios.post) andawait Promise.all(....)them. When all mapped promises resolve thenPromise.allresolves.