AssetLibrary
AssetLibrary
In Contentstack, any files (images, videos, PDFs, audio files, and so on) that you upload get stored in your repository for future use. This repository of uploaded files is called Assets.
sort
The sort method sorts the asset library based on order criteria.
| Name | Type | Description |
|---|---|---|
| keyOrderBy (required) | String | the key order by |
| orderby (required) | ORDERBY | the orderby can be applied using ORDERBY enums |
import com.contentstack.sdk.*; Stack stack = Contentstack.stack( apiKey, deliveryToken, environment); AssetLibrary assets = stack.assetLibrary() assets.sort(keyOrderBy, ORDERBY.ASCENDING);
includeCount
The includeCount method includes the total count of assets in the asset library response.
import com.contentstack.sdk.*; Stack stack = Contentstack.stack( apiKey, deliveryToken, environment); AssetLibrary assets = stack.assetLibrary() assets.includeCount();
includeRelativeUrl
The includeRelativeUrl method includes the relative URLs of assets in the asset library response.
import com.contentstack.sdk.*; Stack stack = Contentstack.stack( apiKey, deliveryToken, environment); AssetLibrary assets = stack.assetLibrary() assets.includeRelativeUrl();
includeMetadata
The includeMetadata method includes the asset library metadata along with the response body.
Stack stack = Contentstack.stack(context, "apiKey", "deliveryToken", environment_name); AssetLibrary assets = stack.assetLibrary(); assets.includeMetadata();
setHeader
The setHeader method adds a header to the request using the specified key and value.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key you want to remove from the header |
| value (required) | String | Value of the header against the key |
import com.contentstack.sdk.*; Stack stack = Contentstack.stack( apiKey, deliveryToken, environment); AssetLibrary assets = stack.assetLibrary() assets.setHeader(key, value);
removeHeader
The removeHeader method removes a header associated with the specified key.
| Name | Type | Description |
|---|---|---|
| key (required) | String | The key you want to remove from the header |
import com.contentstack.sdk.*; Stack stack = Contentstack.stack( apiKey, deliveryToken, environment); AssetLibrary assets = stack.assetLibrary() assets.removeHeader(key);
includeFallback
The includeFallback method includes the fallback language content in the asset response when the specified locale content is unavailable.
import com.contentstack.sdk.*; Stack stack = Contentstack.stack( apiKey, deliveryToken, environment); AssetLibrary assets = stack.assetLibrary() assets.includeFallback()
getCount
The getCount method returns the total number of assets available in the stack.
import com.contentstack.sdk.*; Stack stack = Contentstack.stack( apiKey, deliveryToken, environment); AssetLibrary assets = stack.assetLibrary() assets.getCount()
fetchAll
The fetchAll method retrieves all the assets available in the stack without applying any filters.
| Name | Type | Description |
|---|---|---|
| callback (required) | FetchAssetsCallback | The callback of type FetchAssetsCallback |
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(
apiKey, deliveryToken, environment);
AssetLibrary assets = stack.assetLibrary()
assets.fetchAll(new FetchAssetsCallback({
});where
The where method retrieves assets from the stack by applying filter conditions on any field UID associated with the assets.
| Name | Type | Description |
|---|---|---|
| field_name | String | Enter the field UID of the asset |
| value | String | Enter the value |
Example:
import com.contentstack.sdk.*;
Stack stack = Contentstack.stack(apiKey, deliveryToken, environment);
AssetLibrary assets = stack.assetLibrary().where("field_name","value");
assets.fetchAll(new FetchAssetsCallback(){
@Override
public void onCompletion(ResponseType responseType,List<Asset> assets,Error
error)
{
System.out.println(assets);
}});