Assets
Assets collection
Assets represent files in a space. An asset can be any file, including an image, a video, an audio file, or PDF. Assets are usually attached to entries with links.
You can localize assets by providing separate files for each locale. Assets which are not localized provide a single file under the default locale.
Creating an asset requires three steps and API calls:
- Create an asset.
- Process an asset.
- Publish an asset.
To fetch specific assets use query search parameter.
When using this endpoint, an ID will be automatically generated for the created asset and returned with the response.
Published assets collection
Get all published assets of a space
Retrieves the published versions of all assets in a space.
Asset
Use this endpoint to create a new asset with a specified ID, or update an existing asset with its ID.
X-Contentful-Version.Deleting an asset will remove the current asset and all previously referenced files on the CDN. It can take up to 48 hours until these files will be made unavailable from (assets|images|downloads|videos).ctfassets.net.
Asset processing
To publish an asset, or to preview it within the Contentful web app (under the “Media” tab), you need to process it before. This step is fetching the image from the given location to Contentful’s system. This request might return before the asset processing is finished. The asset will have a fields.file.url for the respective locale if processing completed successfully.
Due to security considerations we forbid users to upload and process files with mime type text/html or text/javascript.
If you want to store HTML files in Contentful, please use application/octet-stream as the contentType. Keep in mind that these files will not be rendered by browsers by default.
Asset publishing
After publishing the asset, it will be available via the Content Delivery API. It will also be available from our asset domain assets.ctfassets.net as specified in the fields.file.url of the asset or if it is an image, it is available from images.ctfassets.net. In this case, you can use query parameters to define the image size, cropping parameters and other options. Find out more in our Images API reference. Published assets do not need any authentication on the Images or Assets API.
Unpublishing will put the asset back into draft state.
Locale-based publishing
To publish or unpublish asset’s fields in certain locales, use the Asset publishing endpoints and pass in the locales in the payload as show in the examples below:
Publish asset locales:
Unpublish asset locales:
Asset archiving
You can only archive an asset when it’s unpublished.
Archiving an asset will remove the current asset and all previously referenced files on the CDN. It can take up to 48 hours until these files will be made unavailable from (assets|images|downloads|videos).ctfassets.net.
Unarchiving an asset will bring back the asset, the current and all previously referenced files into a draft state. It can take up to an hour for the files to be available on the CDN again.