How to use the API download media method


#1

I try to download a media by the API.
I use / library / download / {mediaId} / {moduleType} in a php file but when I start to download, the page loads for a long time then slow down my browser and finally nothing happens.
I think I’m going wrong and I need your help to understand what this method returns.
excuse my bad English :slight_smile:


#2

in browser you could call it with something like that :

http://{{CMSADDRESS}}/api/library/download/{{mediaId}}/{{mediaType}}?access_token={{access_token}}

in code, you could use guzzle with something like that:

$guzzle= new GuzzleHttp\Client();
        $guzzle->request('GET', $sourceCmsAddress . '/api/library/download/' . $mediaId . '/' . $mediaType, [
            'sink' => 'files/' . $fileName,
            'headers' => ['Authorization' => 'Bearer ' . $token]
        ]);

Obviously supplying all the required parameters.


#3

I will try this, thank you very much.
I’ll come back to you if I have another questions


#4

A last question about parameters.
I have no problem for parameters except the filename.
honestly, I don’t know what to put in it


#5

No, don’t consider this question …
I found the solution by myself :):sweat_smile:


#6

finally, I don’t get there.
is the filename the one that is specified in parameters, configuration, location of the library in the xibo interface ?
Or another filename?


#7

the sink in guzzle is pretty much the path to the file ie path to the file where you want to save it after you download it from CMS.


#8

thank you for the answer, I understand better.
i should have looked at the guzzle documentation …
Just a last question, is it possible to let the user choose the folder in which he wants to place the media download rather than fill it in the code?


#9

There are multiple ways you can do that, kind of depending how the script is executed, so you can execute it via command line with arguments then use those in script as variables, you can have a config file and make the script read that and use parameters from it in the code, you can create front end app that will allow user to pass the parameters and then use that in the code etc.


#10

I planned to proceed like this but I won’t miss something.
thank you for your availability.


#11

one more question :sweat_smile:,
I would like to change the name of the media.
Have the real name of the media and not the id.
I specify, I don’t use guzzle but rather via window.location javascript and it works perfectly, but the media is named by the id …