Question

How to bulk upload images using the Content Management API?

  • 11 April 2023
  • 1 reply
  • 184 views

Userlevel 2
Badge

I would like to upload multiple image assets to Contentstack using the Content Management API. 

Using the Upload Asset POST request in the Content Management API method I am able to create a single asset.  I’ve also successfully used the Postman Content Management API Collection  to upload a single asset.  (Code below from Postman codegen).

How can I upload all the images in a folder (or .zip) on my local filesystem to Contentstack using the CMA?

 

const axios = require('axios');

const FormData = require('form-data');

const fs = require('fs');

let data = new FormData();

data.append('asset[upload]', fs.createReadStream('/Users/robertcurlette/_Documents/_Tmp/cmsexperts.png'));



let config = {

method: 'post',

maxBodyLength: Infinity,

url: 'https://api.contentstack.io/v3/assets',

headers: {

'api_key': 'your-api-key',

'authorization': 'your-management-token',

'Content-Type': 'multipart/form-data',

...data.getHeaders()

},

data : data

};



axios.request(config)

.then((response) => {

console.log(JSON.stringify(response.data));

})

.catch((error) => {

console.log(error);

});
 

 


1 reply

Badge

According to the documentation, they don’t seem to offer bulk uploads. The supported bulk operations are: publish, unpublish and delete.

 

I guess you can use the management API to create a folder and then loop through your assets to upload them one by one. You might want to be mindful about rate limiting if you decide to do so. 

 

 

Reply