Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Asset

Hierarchy

  • { fields: { description?: undefined | {}; file: {}; title: {} }; metadata?: MetadataProps; sys: EntityMetaSysProps }
  • DefaultElements<AssetProps>
  • { archive: any; delete: any; isArchived: any; isDraft: any; isPublished: any; isUpdated: any; processForAllLocales: any; processForLocale: any; publish: any; unarchive: any; unpublish: any; update: any }
    • Asset

Index

Properties

fields

fields: { description?: undefined | {}; file: {}; title: {} }

Type declaration

  • Optional description?: undefined | {}

    Description for this asset

  • file: {}

    File object for this asset

    • [key: string]: { contentType: string; details?: Record<string, any>; fileName: string; upload?: undefined | string; uploadFrom?: Record<string, any>; url?: undefined | string }
      • contentType: string
      • Optional details?: Record<string, any>

        Details for the file, depending on file type (example: image size in bytes, etc)

      • fileName: string
      • Optional upload?: undefined | string

        Url where the file is available to be downloaded from, into the Contentful asset system. After the asset is processed this field is gone.

      • Optional uploadFrom?: Record<string, any>
      • Optional url?: undefined | string

        Url where the file is available at the Contentful media asset system. This field won't be available until the asset is processed.

  • title: {}

    Title for this asset

    • [key: string]: string

Optional metadata

metadata: MetadataProps

sys

Methods

archive

  • archive(): Promise<Asset>
  • 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.getEnvironment('<environment_id>'))
    .then((environment) => environment.getAsset('<asset_id>'))
    .then((asset) => asset.archive())
    .then((asset) => console.log(`Asset ${asset.sys.id} archived.`)
    .catch(console.error)

    Returns Promise<Asset>

    Object returned from the server with updated metadata.

delete

  • delete(): Promise<void>
  • 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.getEnvironment('<environment_id>'))
    .then((environment) => environment.getAsset('<asset_id>'))
    .then((asset) => asset.delete())
    .then((asset) => console.log(`Asset deleted.`)
    .catch(console.error)

    Returns Promise<void>

    Promise for the deletion. It contains no data, but the Promise error case should be handled.

isArchived

  • isArchived(): boolean
  • Checks if asset is archived. This means it's not exposed to the Delivery/Preview APIs.

    Returns boolean

isDraft

  • isDraft(): boolean
  • Checks if the asset is in draft mode. This means it is not published.

    Returns boolean

isPublished

  • isPublished(): boolean
  • Checks if the asset is published. A published asset might have unpublished changes

    Returns boolean

isUpdated

  • isUpdated(): boolean
  • Checks if the asset is updated. This means the asset was previously published but has unpublished changes.

    Returns boolean

processForAllLocales

  • Triggers asset processing after an upload, for the files uploaded to all locales of an asset.

    prop

    options.processingCheckWait - Time in milliseconds to wait before checking again if the asset has been processed (default: 500ms)

    prop

    options.processingCheckRetries - Maximum amount of times to check if the asset has been processed (default: 5)

    throws

    {AssetProcessingTimeout} 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.

    example
    const contentful = require('contentful-management')
    
    const client = contentful.createClient({
      accessToken: '<content_management_api_key>'
    })
    client.getSpace('<space_id>')
    .then((space) => space.getEnvironment('<environment_id>'))
    .then((environment) => environment.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

    Returns Promise<Asset>

    Object returned from the server with updated metadata.

processForLocale

  • Triggers asset processing after an upload, for the file uploaded to a specific locale.

    prop

    options.processingCheckWait - Time in milliseconds to wait before checking again if the asset has been processed (default: 500ms)

    prop

    options.processingCheckRetries - Maximum amount of times to check if the asset has been processed (default: 5)

    throws

    {AssetProcessingTimeout} 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.

    example
    const contentful = require('contentful-management')
    
    const client = contentful.createClient({
      accessToken: '<content_management_api_key>'
    })
    client.getSpace('<space_id>')
    .then((space) => space.getEnvironment('<environment_id>'))
    .then((environment) => environment.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

    Returns Promise<Asset>

    Object returned from the server with updated metadata.

publish

  • publish(): Promise<Asset>
  • 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.getEnvironment('<environment_id>'))
    .then((environment) => environment.getAsset('<asset_id>'))
    .then((asset) => asset.publish())
    .then((asset) => console.log(`Asset ${asset.sys.id} published.`)
    .catch(console.error)

    Returns Promise<Asset>

    Object returned from the server with updated metadata.

toPlainObject

unarchive

  • unarchive(): Promise<Asset>
  • 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.getEnvironment('<environment_id>'))
    .then((environment) => environment.getAsset('<asset_id>'))
    .then((asset) => asset.unarchive())
    .then((asset) => console.log(`Asset ${asset.sys.id} unarchived.`)
    .catch(console.error)

    Returns Promise<Asset>

    Object returned from the server with updated metadata.

unpublish

  • unpublish(): Promise<Asset>
  • 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.getEnvironment('<environment_id>'))
    .then((environment) => environment.getAsset('<asset_id>'))
    .then((asset) => asset.unpublish())
    .then((asset) => console.log(`Asset ${asset.sys.id} unpublished.`)
    .catch(console.error)

    Returns Promise<Asset>

    Object returned from the server with updated metadata.

update

  • update(): Promise<Asset>
  • 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.getEnvironment('<environment_id>'))
    .then((environment) => environment.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 Promise<Asset>

    Object returned from the server with updated changes.