Xibo 2.0.0 API Add a image to a Layout

hello,
I would like to know if there is a way to a image to a Layout through the api. If so, could you exemplify?

Hi,
you can replace a media file in the library through the API.
Library add -request uploads a file to the CMS. This API call also makes it possible to replace
a file in the library. You can also specify if you wish to update the file in layouts.
https://xibo.org.uk/manual/api/#/library/libraryAdd

  1. Create layout and assinge a image from the library to it.
  2. Get the mediaId of the file (left most value in the media library for the image).
  3. Send new file with API call, if the request is succesful save the new mediaId for use
    in the next request.

If you want to make the changes in the layouts as quick as possible, you may need to
also make the checkout and publish calls. Checkout on the layout before you upload and publish after. At least in my case this forced the updated files to be downloaded to the player.

Here’s a simple example of the upload with NodeJS RequestJS -library:

UploadToLibrary(file, filepath, mediaID, cb){
var rs = fs.createReadStream(path.normalize(filepath));
if(this.configuration.access_token.length > 1){
var form = new FormData();
form.append(file, fs.createReadStream(filepath));
var headers = {
‘Content-Type’: ‘multipart/form-data’,
‘Authorization’: 'Bearer '+this.configuration.access_token
};
var options = {
url: this.configuration.url+‘library’,
method:‘POST’,
headers: headers,
formData:{
name: file,
files: rs
}
};
if(mediaID){
options.formData.oldMediaId = mediaID;
options.formData.updateInLayouts = 1;
options.formData.deleteOldRevisions = 1;
}
let req = request.post(options, function(err, resp, body){
rs.destroy();
if(err){
console.log('ERROR: file upload failed. '+err);
}else{
if(cb){
cb(body);
}
}
});

}else{
let that = this;
setTimeout(function(){
that.UploadToLibrary(file, filepath);
}, 250);
}
}

1 Like