Agility Management API JS SDK for retrieving media from the Agility CMS
- Source:
Methods
(static) getMediaID(requestParams) → {Promise.<AgilityManagement.Types.MediaReturn>}
Get the ID of a media object in the instance based on it's path.
- Source:
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
requestParams |
Object
|
The paramaters for the API request.
|
Example
import agilityMgmt from '@agility/content-management'
#Create a new instance API client
const api = agilityMgmt.getApi({
location: 'MyLocation',
websiteName: 'MyWebsiteName',
securityKey: 'MySecurityKey'
});
#Set the path to the media
#Important: The path is the file name in Agility Media you need to access
let path = "test.png"
api.getMediaID({
path
})
.then(function(mediaObj) {
#check if media is not null/empty and has valid url for success
})
.catch(function(error) {
#handle error
});
(static) uploadMedia(requestParams) → {Promise.<AgilityManagement.Types.MediaReturn>}
Uploads a file to the media repository.
- Source:
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
requestParams |
Object
|
The paramaters for the API request.
|
Example
import agilityMgmt from '@agility/content-management'
#Create a new instance API client
const api = agilityMgmt.getApi({
location: 'MyLocation',
websiteName: 'MyWebsiteName',
securityKey: 'MySecurityKey'
});
#Create media stream, save blob variable and set filename
let blob = fs.createReadStream('./test/sample/logo.png')
let filename = `test-${new Date().toISOString().replace(/\./g, "").replace(/:/g, "")}.png`;
api.uploadMedia({
fileName: filename,
fileContent: blob
})
.then(function(mediaObj) {
#check if media is not null/empty and has valid url for success
})
.catch(function(error) {
#handle error
});