Logo
⌘K

Uploads

Images that you upload to Artelo are represented by Upload objects.

Bulk Uploads

Our general guideline for uploading a large number of files is to upload multiple files in parallel and poll the API until all files have finished uploading.

// Start uploading each image in parallel
const uploadResponses = await Promise.all(
   images.map(async (image) => {
     const response = await fetch('https://www.artelo.io/api/open/uploads/files/create', {
       method: 'POST',
       headers: {
         'Content-Type': 'application/json',
         Authorization: 'Bearer ...'
       },
       body: JSON.stringify({
         imageUrl: image.url,
         name: image.filename
       })
     });

     return response.json();
   })
 );

 const uploadIds = uploadResponses.map((upload) => upload.id);

 // Poll each upload until all are no longer pending
 while (true) {
   // Wait five seconds before checking again
   await new Promise((r) => setTimeout(r, 5000));

   const uploads = await Promise.all(
     uploadIds.map(async (id) => {
       const response = await fetch(`https://www.artelo.io/api/open/uploads/files/get-by-id?id=${id}`, {
         method: 'GET',
         headers: { Authorization: 'Bearer ...' }
       });

       return response.json();
     })
   );

   const hasPendingUploads = uploads.some((upload) => upload.status === 'Pending');
   if (!hasPendingUploads) {
     break;
   }
 }
Example of how to poll for completed uploads.