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,
});
}
};