---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# NowAttachmentService interface - Android

# NowAttachmentService interface - Android {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 minutes to read

The NowAttachmentService interface provides functions that enable
the manipulation of file attachments and their associated metadata.
{#NowAttachServiceAndroidInterface__table_vx2_klw_5pb__entry__3}

| Name | Type | Description |
|-|-|-|
| configuration | [NowServiceConfiguration](https://servicenow-prod.fluidtopics.net/Csuh2Bp1F37gr9cX8Z4xFg "The NowServiceConfiguration class enables you to configure the ServiceNow instance URL and package name for a feature service.") | Configuration to associate with the service. |
[Table 1. Properties]

{#NowAttachServiceAndroidInterface__table_vx2_klw_5pb}

## NowAttachmentService - attachment(sysId: String, validateAttachment: Boolean =
true) {#ariaid-title2}

Retrieves the attachment with the specified sys_id and optionally validates the
attachment by comparing the computed hash of the attachment to the expected hash.
{#NAttServ-attachment_S_B__table_old_sp5_4pb__entry__3}

| Name | Type | Description |
|-|-|-|
| sysId | String | Sys_id of the attachment to retrieve. This is the sys_id for the attachment on your ServiceNow instance. |
| validateAttachment | Boolean | Flag that indicates whether to validate the attachment. Valid values: * true: Validate the attachment. * false: Do not validate the attachment. {#NAttServ-attachment_S_B__ul_ftq_1q5_4pb} Default: true |
[Table 2. Parameters]

{#NAttServ-attachment_S_B__table_old_sp5_4pb} {#NAttServ-attachment_S_B__table_pld_sp5_4pb__entry__2}

| Type | Description |
|-|-|
| [Call](https://servicenow-prod.fluidtopics.net/QqQzdE2jNcRyZ9uTF8c1wg#CallAndroidInterface "The Call interface represents a request that is prepared for processing.")\<[NowAttachment](https://servicenow-prod.fluidtopics.net/9vUNqa3qYuZqJmheeEbSEQ#NowAttachmentAndroidAPI "The NowAttachment class provides an object that contains an attachment and its associated metadata.")\> | NowAttachment object that contains the requested attachment. |
[Table 3. Returns]

{#NAttServ-attachment_S_B__table_pld_sp5_4pb}  
<br />

    fun getAttachment(sysId: String, isValidateAttachment: Boolean) { 
      val call = attachmentService.attachment(sysId, isValidateAttachment) 
      call.enqueue( 
        { response -> 
          val attachment: NowAttachment? = response.body 
        }, 
          { nowDataError -> handleError(nowDataError) } 
      ) 
    }

## NowAttachmentService - attachmentMetadata(sysId: String) {#ariaid-title3}

Retrieves the metadata for the attachment associated with the specified
sys_id.
{#NAttServ-attachmentMetadata_S__table_bqq_1r5_4pb__entry__3}

| Name | Type | Description |
|-|-|-|
| sysId | String | Sys_id of the attachment whose metadata you want to retrieve. |
[Table 4. Parameters]

{#NAttServ-attachmentMetadata_S__table_bqq_1r5_4pb} {#NAttServ-attachmentMetadata_S__table_cqq_1r5_4pb__entry__2}

| Type | Description |
|-|-|
| [Call](https://servicenow-prod.fluidtopics.net/QqQzdE2jNcRyZ9uTF8c1wg#CallAndroidInterface "The Call interface represents a request that is prepared for processing.")​\<[NowAttachmentMetadata](https://servicenow-prod.fluidtopics.net/bmQG_ojm~RGnPXcxWJ6xpw#NowAttachmentMetadataAndroidAPI "The NowAttachmentMetadata class provides functions that enable you to encode and manage attachment metadata.")\> | Object that contains the metadata for the specified attachment. |
[Table 5. Returns]

{#NAttServ-attachmentMetadata_S__table_cqq_1r5_4pb}  

    fun fetchMetadata(sysId: String) { 
      val call = attachmentService.attachmentMetadata(sysId) 
      call.enqueue(
        { response -> 
          val metadata: NowAttachmentMetadata? = response.body 
        },
        { nowDataError -> handleError(nowDataError) } 
      )
    }

## NowAttachmentService - attachmentMetadata(filter: Filter? = null, limit: Int? =
null) {#ariaid-title4}

Retrieves the metadata for all the attachments that meet the specified
criteria.
{#NAttServ-attachmentMetadata_S_I___table_ujt_zc1_ppb__entry__3}

| Name | Type | Description |
|-|-|-|
| filter | [Filter](https://servicenow-prod.fluidtopics.net/yj8Ot2Apgz6EOHiydE~qEw#FilterAndroidAPI "The Filter class provides the ability to configure filters that define the data to return in the return results of a REST endpoint query.") | Optional. Query string to use to filter the attachments whose metadata to return. Default: null - Returns metadata for all available attachments. Takes into consideration the limit parameter. |
| limit | Integer | Optional. Maximum number of attachment file's metadata to return. Default: null - Returns all metadata that meets the filter parameter specifications. |
[Table 6. Parameters]

{#NAttServ-attachmentMetadata_S_I___table_ujt_zc1_ppb} {#NAttServ-attachmentMetadata_S_I___table_vjt_zc1_ppb__entry__2}

| Type | Description |
|-|-|
| [Call](https://servicenow-prod.fluidtopics.net/QqQzdE2jNcRyZ9uTF8c1wg#CallAndroidInterface "The Call interface represents a request that is prepared for processing.")\<[List](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/)​\<[NowAttachmentMetadata](https://servicenow-prod.fluidtopics.net/bmQG_ojm~RGnPXcxWJ6xpw#NowAttachmentMetadataAndroidAPI "The NowAttachmentMetadata class provides functions that enable you to encode and manage attachment metadata.")\>\> | List of objects that contain the metadata for the matching attachments. |
[Table 7. Returns]

{#NAttServ-attachmentMetadata_S_I___table_vjt_zc1_ppb}  

    fun fetchMultipleMetadata(filterQuery: String, limit: Int) { 
      val call = attachmentService.attachmentMetadata(Filter(filterQuery), limit) 
      call.enqueue( 
        { response -> 
          val metadataList: List<NowAttachmentMetadata>? = response.body 
        },
        { nowDataError -> handleError(nowDataError) } 
      )
    }

## NowAttachmentService - attachmentMetadataPaginator(filter: Filter? = null, limit: Int? =
null) {#ariaid-title5}

Retrieves the metadata for all the attachments that meet the specified criteria and
creates a paginator for iterating through the pages of the returned metadata.
You can use this paginator to navigate through the returned metadata, performing navigation
operations such as fetching the first, last, previous, or next page, or checking whether
there is next or previous page.
{#NAttServ-attachMetadataPaginat_S_I__table_npz_zf1_ppb__entry__3}

| Name | Type | Description |
|-|-|-|
| filter | [Filter](https://servicenow-prod.fluidtopics.net/yj8Ot2Apgz6EOHiydE~qEw#FilterAndroidAPI "The Filter class provides the ability to configure filters that define the data to return in the return results of a REST endpoint query.") | Optional. Query string to use to filter the attachments whose metadata to return. Default: null - Returns metadata for all available attachments. Takes into consideration the limit parameter. |
| limit | Integer | Optional. Maximum number of attachment file's metadata to return. Default: null - Returns all metadata that meets the filter parameter specifications. |
[Table 8. Parameters]

{#NAttServ-attachMetadataPaginat_S_I__table_npz_zf1_ppb} {#NAttServ-attachMetadataPaginat_S_I__table_opz_zf1_ppb__entry__2}

| Type | Description |
|-|-|
| Paginator​\<[NowAttachmentMetadata](https://servicenow-prod.fluidtopics.net/bmQG_ojm~RGnPXcxWJ6xpw#NowAttachmentMetadataAndroidAPI "The NowAttachmentMetadata class provides functions that enable you to encode and manage attachment metadata.")\> | Success: Paginator object along with the specified pages of metadata. Failure: NowDataError object. |
[Table 9. Returns]

{#NAttServ-attachMetadataPaginat_S_I__table_opz_zf1_ppb}  
The following code example shows how to call this function.

    suspend fun createAttachmentMetadataPaginator() {
      val filterQuery: String = "content_type=text/plain"
      val filter = filterQuery.let(::Filter)
      val limit = 10
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(filter, limit)
        ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {
          override fun onFailure(e: NowDataError) {
            handleError(e)
          }

          override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {
            handleResponse(response)
          }

        })
        ?: throw Exception("Response is null")
    }

## NowAttachmentService - delete(sysId: String) {#ariaid-title6}

Deletes the attachment with the specified sys_id.
{#NAttServ-delete_S__table_dq4_dj1_ppb__entry__3}

| Name | Type | Description |
|-|-|-|
| sysId | String | Sys_id of the attachment to delete. |
[Table 10. Parameters]

{#NAttServ-delete_S__table_dq4_dj1_ppb} {#NAttServ-delete_S__table_eq4_dj1_ppb__entry__2}

| Type | Description |
|-|-|
| [Call](https://servicenow-prod.fluidtopics.net/QqQzdE2jNcRyZ9uTF8c1wg#CallAndroidInterface "The Call interface represents a request that is prepared for processing.")\<[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/)\> | Success: Nothing is returned. Failure: NowDataError returned. |
[Table 11. Returns]

{#NAttServ-delete_S__table_eq4_dj1_ppb}  
<br />

    fun deleteAttachment(sysId: String) { 
      val call = attachmentService.delete(sysId) 
      call.enqueue( 
        { response -> handleResponse(response) }, 
        { nowDataError -> handleError(nowDataError) } 
      )
    } 

## NowAttachmentService - upload(data: ByteArray, configuration:
NowAttachmentUploadConfiguration) {#ariaid-title7}

Retrieves the metadata for all the attachments that meet the specified criteria and
creates a paginator for iterating through pages of the returned metadata.
{#NAttServ-upload_A_O__table_fkj_3k1_ppb__entry__3}

| Name | Type | Description |
|-|-|-|
| data | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/) | Metadata to upload and associate with the attachment specified in the configuration object. |
| configuration | NowAttachmentUploadConfiguration | Upload configuration parameters. |
[Table 12. Parameters]

{#NAttServ-upload_A_O__table_fkj_3k1_ppb} {#NAttServ-upload_A_O__table_gkj_3k1_ppb__entry__2}

| Type | Description |
|-|-|
| [NowAttachmentMetadata](https://servicenow-prod.fluidtopics.net/bmQG_ojm~RGnPXcxWJ6xpw#NowAttachmentMetadataAndroidAPI "The NowAttachmentMetadata class provides functions that enable you to encode and manage attachment metadata.") | Uploaded metadata. |
[Table 13. Returns]

{#NAttServ-upload_A_O__table_gkj_3k1_ppb}  

    fun uploadAttachment(tableName: String, recordSysId: String, fileName: String) { 
      val bitmap = BitmapFactory.decodeResource(resources, R.drawable.test_image) 
      val data = bitmap.compress(ImageType.JPEG) 
      val contentType = "image/jpg" 
      val config = NowAttachmentUploadConfiguration(tableName, recordSysId, fileName, contentType) 
      val call = attachmentService.upload(data, config) 
     
      call.enqueue( 
        { response -> 
          val uploadedAttachmentMetadata: NowAttachmentMetadata? = response.body 
        },
        { nowDataError -> handleError(nowDataError) } 
      )
    }


