Just wondering if there is a way to replace an existing media item using the API and keep the same media ID? The same way you can do it through the GUI and update all layouts at the same time?
After reading through the code, I think I have figured this out.
You must post to /api/library/mcaas/{mediaId}
Just wondering if there is a reason for calling $accessToken->expire(); in the macaas function?
Secondly, every time I upload via the api my files get saved into âapi/libraryâ rather then my default file store. Am I doing something wrong? How can I save to âfiles/â ?
I think youâve misunderstood how the GUI works.
When you replace a file in the GUI, it always gets a new media ID.
If you choose to update all instances, then the CMS simply visits all the layouts that media is used in and updates the link to the newly uploaded media ID.
The mcaas API call is not what you want at all. I think what youâd do is use the media edit route in the API, ensuring you pass the flag to update the media in all layouts:
http://xibo.org.uk/manual-tempel/api/#!/library/libraryEdit
Iâm not certain of the exact mechanics of that. Iâm sure @dan can add any further pointers if needed.
With regard to the file upload location, at a guess, you perhaps havenât set a fully qualified path to the CMS library in the CMS settings. Ensure the path you entered is complete there.
This is not very well documented iâm afraid - when you edit a media item and want to replace the associated file, you need to call the post routine: http://xibo.org.uk/manual-tempel/api/#!/library/libraryAdd
You need to make sure you provide the oldMediaId as a POST parameter, which will actually trigger the replace.
If you are comfortable looking in code this is the end point: https://github.com/xibosignage/xibo-cms/blob/develop/lib/Controller/Library.php#L500
There is an example for adding a new file here: https://github.com/xibosignage/oauth2-xibo-cms/blob/master/example/file.php#L30, in the case of an edit youâd just add the oldMediaId to the multi-part post data.
The mcaas route expires tokens because they are âone-shotâ tokens created for use in media conversion routines (not replacement/edits)
Thanks guys, with both of your suggestions I have it working in poster. Really appreciate your help!
I have Authentication, GET and POST working in PHP, with the exception of the multipart image post. I keep getting âFiletype not allowedâ. I am not using guzzle, just a drupal httpclient. Would it be possible to get any pointers on where I might be going wrong with the below code (similar code works for the Auth request):
$file = fopen($imageURL,ârâ);
$post_data = array(
array(
ânameâ => ânameâ,
âcontentsâ => âapi upâ
),
array(
ânameâ => âfilesâ,
âcontentsâ => $file
)
);
$url = $endpoint . 'library'; $postRequest = new HttpClientRequest($url, array( 'method' => HttpClientRequest::METHOD_POST, 'headers' => array('Content-Type' => array('multipart/formdata; boundary=----WebKitFormBoundaryzUd5n1AiZ0wdjlAL')), 'data' => $post_data )); $postRequest->addHeader('Authorization', 'Bearer ' . $access_key);
try {
$resp = $client->execute($postRequest);
}
catch (Exception $e) {
watchdog(âXiboâ, âFailed to POSTâ);
}
This usually means that the file cannot be retrieved from the HTTP request - iâm guessing because itâs not formatted as a multipart message.
Iâve not used Drupal before, but from what iâve read Drupal 8 uses Guzzle under the hood. That being said I canât find documentation for HttpClientRequest - it looks like it might be this library?
Do you have any documentation on that library?
I decided just to install guzzle and I now have the Xibo api working with my Drupal site. Itâs absolutely brilliant - keep up the good work guys!