// Start uploading each image in parallel
await Promise.all(
images.map(async (image) =>
fetch('https://www.artelo.io/api/open/uploads/create', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ...'
},
body: JSON.stringify({
imageUrl: image.url,
name: image.filename
})
})
)
);
// Poll the number of pending uploads until all are no longer pending
let pendingCount = 0;
do {
// Wait five seconds before checking again
await new Promise((r) => setTimeout(r, 5000));
const response = await fetch('https://www.artelo.io/api/open/uploads/get-counts-by-status', {
method: 'GET',
headers: { Authorization: 'Bearer ...' }
});
const uploadCounts = await response.json();
pendingCount = uploadCounts.Pending;
} while (pendingCount > 0);