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