- Source:
Assets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded in your Contentstack repository for future use.
These files can be attached and used in multiple entries. Read more about Assets.
Methods
(static) update() → {Promise.<Asset.Asset>}
- Source:
The Update Asset call lets you update the name and description of an existing Asset.
Example
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).asset('uid').fetch()
.then((asset) => {
asset.title = 'My New asset'
asset.description = 'Asset description'
return asset.update()
})
.then((asset) => console.log(asset))
Returns:
Promise for Asset instance
- Type
- Promise.<Asset.Asset>
(static) delete() → {Object}
- Source:
The Delete asset call will delete an existing asset from the stack.
Example
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).asset('uid').delete()
.then((response) => console.log(response.notice))
Returns:
Response Object.
- Type
- Object
(static) fetch() → {Promise.<Asset.Asset>}
- Source:
The fetch an asset call returns comprehensive information about a specific version of an asset of a stack.
Example
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).asset('uid').fetch()
.then((asset) => console.log(asset))
Returns:
Promise for Asset instance
- Type
- Promise.<Asset.Asset>
(static) replace() → {Promise.<Asset.Asset>}
- Source:
The Replace asset call will replace an existing asset with another file on the stack.
Example
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
const asset = {
upload: 'path/to/file.png',
}
client.stack({ api_key: 'api_key'}).asset('uid').replace(asset)
.then((asset) => console.log(asset))
Returns:
Promise for Asset instance
- Type
- Promise.<Asset.Asset>
(static) publish() → {Promise.<Object>}
- Source:
The Publish an asset call is used to publish a specific version of an asset on the desired environment either immediately or at a later date/time.
Example
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
const asset = {
"locales": [
"en-us"
],
"environments": [
"development"
]
}
client.stack({ api_key: 'api_key'}).asset('uid').publish({ publishDetails: asset, version: 1, scheduledAt: "2019-02-08T18:30:00.000Z"})
.then((response) => console.log(response.notice))
Returns:
Response Object.
- Type
- Promise.<Object>
(static) unpublish() → {Promise.<Object>}
- Source:
The Replace asset call will replace an existing asset with another file on the stack.
Example
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
const asset = {
"locales": [
"en-us"
],
"environments": [
"development"
]
}
client.stack({ api_key: 'api_key'}).asset('uid').unpublish({ publishDetails: asset, version: 1, scheduledAt: "2019-02-08T18:30:00.000Z"})
.then((response) => console.log(response.notice))
Returns:
Response Object.
- Type
- Promise.<Object>
(static) folder() → {Promise.<Folder.Folder>}
- Source:
The Folder allows to fetch and create folders in assets.
Example
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
const asset = {name: 'My New contentType'}
client.stack({ api_key: 'api_key'}).asset('uid').folder().create({ asset })
.then((folder) => console.log(folder))
Returns:
Promise for Entry instance
- Type
- Promise.<Folder.Folder>
(static) create() → {Promise.<Asset.Asset>}
- Source:
The Create an asset call creates a new asset.
Example
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
const asset = {
upload: 'path/to/file.png',
title: 'Title',
description: 'Desc'
}
client.stack({ api_key: 'api_key'}).asset().create(asset)
.then((asset) => console.log(asset))
Returns:
Promise for Asset instance
- Type
- Promise.<Asset.Asset>
(static) query(params) → {Array.<Asset>}
- Source:
Properties:
Name | Type | Description |
---|---|---|
params.query |
Object | Queries that you can use to fetch filtered results. |
The Query on Asset will allow to fetch details of all or specific Asset.
Example
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).asset().query({ query: { filename: 'Asset Name' } }).find()
.then((asset) => console.log(asset))
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | URI parameters |
Returns:
Array of Asset.
- Type
- Array.<Asset>
(static) download() → {Array.<AssetResponse>}
- Source:
The Download function will get downloadable file in specified format.
Examples
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).asset('uid').fetch()
.then((asset) => asset.download({responseType: 'blob'}))
.then((response) => // Write response data to destination file. )
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).asset().download({url: 'asset_url_to_download', responseType: 'blob'})
.then((response) => // Write response data to destination file. )
Parameters:
Name | Type | Description |
---|---|---|
param.url |
* | The url for the asset to download |
param.responseType |
* | Optional parameter to specify the response type. |
Returns:
Array of Asset.
- Type
- Array.<AssetResponse>