Since Cockpit doesn’t easily support saving image files through an api call, I thought of saving images on an external API. So i tried the following:
Post http://otherimageurl.com/image.jpg  tohttp:mycockpitcmsurl.com/api/collections/save/collectionname
in the field
But cockpit saves its own base url in front of my external image url.
             
            
              
            
           
          
            
              
                artur  
              
                  
                    April 19, 2019,  1:01pm
                   
                  2 
               
             
            
              there is an add assets api entry point:
/api/cockpit/addAssets
             
            
              
            
           
          
            
            
              I never tried it before and tested it now. It works well. Make sure, to name your key files[].
Javascript example: https://github.com/agentejo/cockpit/issues/763#issuecomment-434509812 
Postman example:
             
            
              2 Likes 
            
                
            
           
          
            
            
              Hi, this example doesn’t work for me. Is there another solution now to send images via API?
             
            
              
            
           
          
            
              
                abernh  
              
                  
                    October 18, 2021,  8:26am
                   
                  5 
               
             
            
              What is it that you are trying to accomplish? And in which way does the example not work out as expected?
             
            
              
            
           
          
            
            
              Hi, It works very well, I forgot to declare the file as a file.
var axios = require('axios');
var FormData = require('form-data');
var fs = require('fs');
var data = new FormData();
data.append('files[]', fs.createReadStream('/C:/Users/***/img.jpg'));
data.append('meta[folder]', '');
var config = {
  method: 'post',
  url: '**/api/cockpit/addAssets?token=**',
  headers: { 
    'Authorization': 'Bearer **', 
    ...data.getHeaders()
  },
  data : data
};
axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});