Class Asset


  • public class Asset
    extends Object
    MIT License Copyright (c) 2012 - 2019 Contentstack Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    • Constructor Detail

      • Asset

        protected Asset()
      • Asset

        protected Asset​(String assetUid)
    • Method Detail

      • setStackInstance

        protected void setStackInstance​(Stack stack)
      • configure

        public Asset configure​(org.json.JSONObject jsonObject)
        Creates new instance of Asset from valid JSONObject. 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 filled Entry and configure(JSONObject).


        Example :

        1. Single Attachment :-
          //'blt5d4sample2633b' is a dummy Application API key
         Stack stack = Contentstack.stack(context, "blt5d4sample2633b", "bltdtsample_accessToken767vv",  config);
         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.
      • setHeader

        public void setHeader​(String key,
                              String value)
        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 :
         //'blt5d4sample2633b' is a dummy Application API key
         Asset assetObject = Contentstack.stack(context, "blt5d4sample2633b", "bltdtsample_accessToken767vv",  config).asset("assetUid");
         assetObject.setHeader("custom_header_key", "custom_header_value");
         
      • removeHeader

        public void removeHeader​(String key)
        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(context, "blt5d4sample2633b", "bltdtsample_accessToken767vv",  config).asset("assetUid");
         assetObject.removeHeader("custom_header_key");
         
      • setUid

        protected void setUid​(String assetUid)
        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(context, "blt5d4sample2633b", "bltdtsample_accessToken767vv",  config).asset("assetUid");
         assetObject.setUid("upload_uid");
         
      • getAssetUid

        public String getAssetUid()
        Returns:
        String @assetUid

        Example :
         String uid = assetObject.getAssetUid();
         return String of @uid
         
      • getFileType

        public String getFileType()
        Returns:
        String @contentType

        Example :
         String contentType = assetObject.getFileType();
         
      • getFileSize

        public String getFileSize()
        Returns:
        String @fileSize
        Note :
        file size will receive in bytes number.

        Example :
         String queueSize = assetObject.getFileSize();
         
      • getFileName

        public String getFileName()
        Returns:
        String @fileName

        Example :
         String fileName = assetObject.getFileName();
         
      • getUrl

        public String 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

        public Calendar getCreateAt()
        Returns:
        Calendar @Date Get Calendar value of creation time of entry.

        Example :
         Calendar createdAt = assetObject.getCreateAt("key");
         
      • getCreatedBy

        public String getCreatedBy()
      • getUpdateAt

        public Calendar getUpdateAt()
        Get Calendar value of updating time of entry.
        Returns:
        Calendar @Date

        Example :
         Calendar updatedAt = assetObject.getUpdateAt("key");
         
      • getUpdatedBy

        public String getUpdatedBy()
        Get uid who updated this entry.
        Returns:
        String @getUpdatedBy

        Example :
         String updatedBy_uid = assetObject.getUpdatedBy();
         
      • getDeleteAt

        public Calendar getDeleteAt()
        Get Calendar value of deletion time of entry
        Returns:
        Calendar @Date

        Example :
         Calendar updatedAt = entry.getUpdateAt("key");
         
      • getDeletedBy

        public String getDeletedBy()
        Get uid who deleted this entry.
        Returns:
        String @getDeletedBy

        Example :
         String deletedBy_uid = assetObject.getDeletedBy();
         
      • getTags

        public String[] getTags()
        Get tags.
        Returns:
        String @tagsArray

        Example :
         String[] tags = assetObject.getURL();
         
      • fetch

        public void fetch​(FetchResultCallback callback)
        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

        public Asset addParam​(String key,
                              String value)
        This method adds key and value to an Entry.
        Parameters:
        key - The key as string which needs to be added to an Asset
        value - 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.
                  }
            }
          });