- Source:
Asset instances
Methods
(static) archive() → {Promise.<Asset>}
- Source:
Archives the object
Example
const contentful = require('contentful-management')
const client = contentful.createClient({
accessToken: '<content_management_api_key>'
})
client.getSpace('<space_id>')
.then((space) => space.getAsset('<asset_id>'))
.then((asset) => asset.archive())
.then((asset) => console.log(`Asset ${asset.sys.id} archived.`)
.catch(console.error)
Returns:
Object returned from the server with updated metadata.
- Type
- Promise.<Asset>
(static) delete() → {Promise}
- Source:
Deletes this object on the server.
Example
const contentful = require('contentful-management')
const client = contentful.createClient({
accessToken: '<content_management_api_key>'
})
client.getSpace('<space_id>')
.then((space) => space.getAsset('<asset_id>'))
.then((asset) => asset.delete())
.then((asset) => console.log(`Asset deleted.`)
.catch(console.error)
Returns:
Promise for the deletion. It contains no data, but the Promise error case should be handled.
- Type
- Promise
(static) isArchived() → {boolean}
- Source:
Checks if asset is archived. This means it's not exposed to the Delivery/Preview APIs.
Returns:
- Type
- boolean
(static) isDraft() → {boolean}
- Source:
Checks if the asset is in draft mode. This means it is not published.
Returns:
- Type
- boolean
(static) isPublished() → {boolean}
- Source:
Checks if the asset is published. A published asset might have unpublished changes (@see {Asset.isUpdated})
Returns:
- Type
- boolean
(static) isUpdated() → {boolean}
- Source:
Checks if the asset is updated. This means the asset was previously published but has unpublished changes.
Returns:
- Type
- boolean
(static) processForAllLocales(options) → {Promise.<Asset>}
- Source:
Properties:
Name | Type | Description |
---|---|---|
options.processingCheckWait |
number | Time in milliseconds to wait before checking again if the asset has been processed (default: 500ms) |
options.processingCheckRetries |
number | Maximum amount of times to check if the asset has been processed (default: 5) |
Triggers asset processing after an upload, for the files uploaded to all locales of an asset.
Example
const contentful = require('contentful-management')
const client = contentful.createClient({
accessToken: '<content_management_api_key>'
})
client.getSpace('<space_id>')
.then((space) => space.createAssetWithId('<asset_id>', {
title: {
'en-US': 'Playsam Streamliner',
'de-DE': 'Playsam Streamliner'
},
file: {
'en-US': {
contentType: 'image/jpeg',
fileName: 'example.jpeg',
upload: 'https://example.com/example.jpg'
},
'de-DE': {
contentType: 'image/jpeg',
fileName: 'example.jpeg',
upload: 'https://example.com/example-de.jpg'
}
}
}))
.then((asset) => asset.processForAllLocales())
.then((asset) => console.log(asset))
.catch(console.error)
Parameters:
Name | Type | Description |
---|---|---|
options |
object | Additional options for processing |
Throws:
-
If the asset takes too long to process. If this happens, retrieve the asset again, and if the url property is available, then processing has succeeded. If not, your file might be damaged.
- Type
- AssetProcessingTimeout
Returns:
Object returned from the server with updated metadata.
- Type
- Promise.<Asset>
(static) processForLocale(locale, options) → {Promise.<Asset>}
- Source:
Properties:
Name | Type | Description |
---|---|---|
options.processingCheckWait |
number | Time in milliseconds to wait before checking again if the asset has been processed (default: 500ms) |
options.processingCheckRetries |
number | Maximum amount of times to check if the asset has been processed (default: 5) |
Triggers asset processing after an upload, for the file uploaded to a specific locale.
Example
const contentful = require('contentful-management')
const client = contentful.createClient({
accessToken: '<content_management_api_key>'
})
client.getSpace('<space_id>')
.then((space) => space.createAssetWithId('<asset_id>', {
title: {
'en-US': 'Playsam Streamliner',
},
file: {
'en-US': {
contentType: 'image/jpeg',
fileName: 'example.jpeg',
upload: 'https://example.com/example.jpg'
}
}
}))
.then((asset) => asset.processForLocale('en-US'))
.then((asset) => console.log(asset))
.catch(console.error)
Parameters:
Name | Type | Description |
---|---|---|
locale |
string | Locale which processing should be triggered for |
options |
object | Additional options for processing |
Throws:
-
If the asset takes too long to process. If this happens, retrieve the asset again, and if the url property is available, then processing has succeeded. If not, your file might be damaged.
- Type
- AssetProcessingTimeout
Returns:
Object returned from the server with updated metadata.
- Type
- Promise.<Asset>
(static) publish() → {Promise.<Asset>}
- Source:
Publishes the object
Example
const contentful = require('contentful-management')
const client = contentful.createClient({
accessToken: '<content_management_api_key>'
})
client.getSpace('<space_id>')
.then((space) => space.getAsset('<asset_id>'))
.then((asset) => asset.publish())
.then((asset) => console.log(`Asset ${asset.sys.id} published.`)
.catch(console.error)
Returns:
Object returned from the server with updated metadata.
- Type
- Promise.<Asset>
(static) unarchive() → {Promise.<Asset>}
- Source:
Unarchives the object
Example
const contentful = require('contentful-management')
const client = contentful.createClient({
accessToken: '<content_management_api_key>'
})
client.getSpace('<space_id>')
.then((space) => space.getAsset('<asset_id>'))
.then((asset) => asset.unarchive())
.then((asset) => console.log(`Asset ${asset.sys.id} unarchived.`)
.catch(console.error)
Returns:
Object returned from the server with updated metadata.
- Type
- Promise.<Asset>
(static) unpublish() → {Promise.<Asset>}
- Source:
Unpublishes the object
Example
const contentful = require('contentful-management')
const client = contentful.createClient({
accessToken: '<content_management_api_key>'
})
client.getSpace('<space_id>')
.then((space) => space.getAsset('<asset_id>'))
.then((asset) => asset.unpublish())
.then((asset) => console.log(`Asset ${asset.sys.id} unpublished.`)
.catch(console.error)
Returns:
Object returned from the server with updated metadata.
- Type
- Promise.<Asset>
(static) update() → {Promise.<Asset>}
- Source:
Sends an update to the server with any changes made to the object's properties
Example
const contentful = require('contentful-management')
const client = contentful.createClient({
accessToken: '<content_management_api_key>'
})
client.getSpace('<space_id>')
.then((space) => space.getAsset('<asset_id>'))
.then((asset) => {
asset.fields.title['en-US'] = 'New asset title'
return asset.update()
})
.then((asset) => console.log(`Asset ${asset.sys.id} updated.`)
.catch(console.error)
Returns:
Object returned from the server with updated changes.
- Type
- Promise.<Asset>
Type Definitions
Asset
- Source:
Properties:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sys |
Meta.Sys | Standard system metadata with additional asset specific properties
Properties
|
||||||||||||||||||||||||||||||||||||
fields |
Object | Object with content for each field
Properties
|
||||||||||||||||||||||||||||||||||||
toPlainObject() |
function | Returns this Asset as a plain JS object |