Package com.contentstack.sdk
Class Asset
java.lang.Object
com.contentstack.sdk.Asset
public class Asset extends Object
Asset refer to the media file (images, videos, PDFs, audio files, and so on)
uploaded to Contentstack. These files can be used in multiple entries.
-
Field Summary
Fields Modifier and Type Field Description protected String
assetUid
protected String
contentType
protected String
fileName
protected String
fileSize
protected LinkedHashMap<String,Object>
headerGroup_app
protected LinkedHashMap<String,Object>
headerGroup_local
protected org.json.JSONObject
json
protected Stack
stackInstance
protected String[]
tagsArray
protected String
uploadUrl
org.json.JSONObject
urlQueries
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description Asset
addParam(String key, String value)
This method adds key and value to an Entry.Asset
configure(org.json.JSONObject jsonObject)
Creates new instance ofAsset
from validJSONObject
.void
fetch(FetchResultCallback callback)
Fetch a particular asset using uid.String
getAssetUid()
Calendar
getCreateAt()
String
getCreatedBy()
Calendar
getDeleteAt()
GetCalendar
value of deletion time of entryString
getDeletedBy()
Get uid who deleted this entry.String
getFileName()
String
getFileSize()
String
getFileType()
String[]
getTags()
Get tags.Calendar
getUpdateAt()
GetCalendar
value of updating time of entry.String
getUpdatedBy()
Get uid who updated this entry.String
getUrl()
Asset
includeDimension()
Include the dimensions (height and width) of the image in the response.Asset
includeFallback()
Retrieve the published content of the fallback locale if an entry is not localized in specified localevoid
removeHeader(String key)
Remove a header for a given key from headers.void
setHeader(String key, String value)
To set headers for Contentstack rest calls.protected void
setStackInstance(Stack stack)
protected Asset
setTags(String[] tags)
protected void
setUid(String assetUid)
To set uid of media file which is uploaded on Contentstack server.org.json.JSONObject
toJSON()
-
Field Details
-
assetUid
-
contentType
-
fileSize
-
fileName
-
uploadUrl
-
json
protected org.json.JSONObject json -
tagsArray
-
urlQueries
public org.json.JSONObject urlQueries -
headerGroup_app
-
headerGroup_local
-
stackInstance
-
-
Constructor Details
-
Method Details
-
setStackInstance
-
configure
Creates new instance ofAsset
from validJSONObject
. If JSON object is not appropriate then it will return null.- Parameters:
jsonObject
- json object of particular file attached in the built object.
Asset
can be generate using of data filledEntry
andJSONObject
.
Example :
1. Single Attachment :-
//'blt5d4sample2633b' is a dummy Application API key Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment"); Asset assetObject = stack.asset("assetUid"); assetObject.configure(entryObject.getJSONObject(attached_image_field_uid));
2. Multiple Attachment :-
JSONArray array = entryObject.getJSONArray(Attach_Image_Field_Uid);
for (int i = 0; i < array.length(); i++)
{ Asset assetObject = stack.asset("assetUid"); assetObject.configure(entryObject.getJSONObject(attached_image_field_uid)); }- Returns:
Asset
instance.
-
setTags
-
setHeader
To set headers for Contentstack rest calls.
Scope is limited to this object only.- Parameters:
key
- header name.value
- header value against given header name.
Example :
Asset assetObject = Contentstack.stack( "blt5d4sample2633b", "bltdtsample_accessToken767vv", config).asset("assetUid"); assetObject.setHeader("custom_header_key", "custom_header_value");
-
removeHeader
Remove a header for a given key from headers.
Scope is limited to this object only- Parameters:
key
- header key.
Example :
//'blt5d4sample2633b' is a dummy Application API key Asset assetObject = Contentstack.stack("blt5d4sample2633b", "bltdtsample_accessToken767vv", config).asset("assetUid"); assetObject.removeHeader("custom_header_key");
-
setUid
To set uid of media file which is uploaded on Contentstack server.- Parameters:
assetUid
- upload uid.
Example :
//'blt5d4sample2633b' is a dummy Application API key Asset assetObject = Contentstack.stack("blt5d4sample2633b", "bltdtsample_accessToken767vv", config).asset("assetUid"); assetObject.setUid("upload_uid");
-
getAssetUid
- Returns:
- String @assetUid
Example :
String uid = assetObject.getAssetUid(); return String of @uid
-
getFileType
- Returns:
- String @contentType
Example :
String contentType = assetObject.getFileType();
-
getFileSize
- Returns:
- String @fileSize
Note :
file size will receive in bytes number.
Example :
String queueSize = assetObject.getFileSize();
-
getFileName
- Returns:
- String @fileName
Example :
String fileName = assetObject.getFileName();
-
getUrl
- Returns:
- String @uploadUrl by which you can download media file uploaded on Contentstack server.
You will get uploaded url after uploading media file on Contentstack server.
Example :
String url = assetObject.getUrl();
-
toJSON
public org.json.JSONObject toJSON()- Returns:
- JSON @json representation of this
Asset
instance data.
Example :
JSONObject json = assetObject.toJSON();
-
getCreateAt
-
getCreatedBy
-
getUpdateAt
GetCalendar
value of updating time of entry.- Returns:
- Calendar @
Date
Example :
Calendar updatedAt = assetObject.getUpdateAt("key");
-
getUpdatedBy
Get uid who updated this entry.- Returns:
- String @getUpdatedBy
Example :
String updatedBy_uid = assetObject.getUpdatedBy();
-
getDeleteAt
GetCalendar
value of deletion time of entry- Returns:
- Calendar @
Date
Example :
Calendar updatedAt = entry.getUpdateAt("key");
-
getDeletedBy
Get uid who deleted this entry.- Returns:
- String @getDeletedBy
Example :
String deletedBy_uid = assetObject.getDeletedBy();
-
getTags
Get tags.- Returns:
- String @tagsArray
Example :
String[] tags = assetObject.getURL();
-
includeDimension
Include the dimensions (height and width) of the image in the response. Supported image types: JPG, GIF, PNG, WebP, BMP, TIFF, SVG, and PSD- Returns:
- Asset
-
fetch
Fetch a particular asset using uid.- Parameters:
callback
-FetchResultCallback
instance for success and failure result.
Example :
Asset asset = stack.asset("blt5312f71416d6e2c8"); asset.fetch(new FetchResultCallback() { @Override public void onCompletion(ResponseType responseType, Error error) { if(error == null){ //Success Block. }else { //Fail Block. } } });
-
addParam
This method adds key and value to an Entry.- Parameters:
key
- The key as string which needs to be added to an Assetvalue
- The value as string which needs to be added to an Asset- Returns:
Asset
Example :
final Asset asset = stack.asset("blt5312f71416d6e2c8"); asset.addParam("key", "some_value"); asset.fetch(new FetchResultCallback() { @Override public void onCompletion(ResponseType responseType, Error error) { if(error == null){ //Success Block. }else { //Fail Block. } } });
-
includeFallback
Retrieve the published content of the fallback locale if an entry is not localized in specified locale- Returns:
Asset
object, so you can chain this call.
Example :
Stack stack = Contentstack.stack("ApiKey", "deliveryToken", "environment"); final Asset asset = stack.asset("asset_uid"); asset.includeFallback();
-