---
sourceDocument: Xanadu API 참조
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ko-KR/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - ko-KR

ft:publication_title :

    - Xanadu API 참조

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# 첨부 파일 및 첨부 파일 메타데이터 검색

# 첨부 파일 및 첨부 파일 메타데이터 검색 {#ariaid-title1}

* 릴리스 버전: Xanadu
* 
* 업데이트 날짜 2024년 08월 01일
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 소요 시간: 5분

NowAttachmentService API를 사용하면 첨부 파일에 대한 CRUD 작업을 수행하고 인스턴스에서 첨부 파일 메타데이터를 검색할 수 있습니다ServiceNow.
주:  
NowAttachment API는 기본 ServiceNow 시스템의 게스트 사용자에 대해 작동합니다.  
이 API를 사용하여 다음을 수행할 수 있습니다.

* 첨부 파일을 ServiceNow 인스턴스에 업로드하고 특정 기록에 연결합니다.
* 하나 이상의 첨부 파일을 다운로드합니다.
* 첨부 파일을 삭제합니다.
* 첨부 파일의 계산된 해시를 예상 해시와 비교하여 첨부 파일의 유효성을 확인합니다.
* 첨부 파일 메타데이터를 다운로드합니다. 이 메타데이터는 첨부 파일이 업로드될 때 인스턴스에서 생성됩니다 ServiceNow .
{#mobsdk-and-retrieve_attach_metadata__ul_l5y_qjw_3qb}

첨부 파일 작업에 대한 자세한 내용은 [첨부 파일 API](https://servicenow-prod.fluidtopics.net/gX4bx2Omvufshsmqj6LXHw#c_AttachmentAPI "첨부 파일 API는 첨부 파일을 업로드하고 쿼리할 수 있는 엔드포인트를 제공합니다.")를 참조하십시오.  
다음은 NowAttachmentService를 인스턴스화하는 방법을 보여 줍니다.

    /**
     * Helper class used to handle different Now service instances. 
     * It has an application scope or is a Singleton.
     */
    @Singleton
    class SdkManager @Inject constructor() {


        private var nowAttachmentService: NowAttachmentService? = null

        /**
         * Create the NowAttachmentService once in the lifetime of the application 
         * inside the Application class or another manager class
         * that will be injected into other classes via dagger/hilt.
         * NowAttachmentService should be created after initializing the NowSDK
         */
        suspend fun getNowAttachmentService(): NowAttachmentService? {
            if (nowAttachmentService != null) return nowAttachmentService

            return NowDataSDK.makeAttachmentService(URL("https://instance-name.service-now.com"))
                .getOrThrow()
                .also { this.nowAttachmentService = it }
        }
    }

다음은 특정 첨부 파일에 대한 메타데이터를 가져오는 [Call](https://servicenow-prod.fluidtopics.net/EfE7tICr3353oOPmB9qPZw#CallAndroidInterface "호출 인터페이스는 처리를 위해 준비된 요청을 나타냅니다.") 개체를 가져오는 방법을 보여 줍니다. 지정된 요청을 수행하고 `Response<NowAttachmentMetadata>`를 반환할 수 있는 실행 가능한 개체를 만듭니다.  

    suspend fun fetchMetadata(sysId: String) {
        val response = runCatching {
            sdkManager.getNowAttachmentService()?.attachmentMetadata(sysId)?.execute()
        }

        if (response.isSuccess) {
            val nowAttachmentMetadata = response.getOrNull()?.body
        } else {
            Log.e("NowSDK", "result not successful")
        }
    }

다음은 여러 첨부 파일에 대한 메타데이터를 가져오는 Call 개체를 가져오는 [방법을](https://servicenow-prod.fluidtopics.net/EfE7tICr3353oOPmB9qPZw#CallAndroidInterface "호출 인터페이스는 처리를 위해 준비된 요청을 나타냅니다.") 보여 줍니다. 지정된 요청을 수행하고 `Response< List<NowAttachmentMetadata>>`를 반환할 수 있는 실행 가능한 개체를 만듭니다.  

    suspend fun fetchMultipleMetadata() {
        val filterQuery = "content_type=text/plain"
        val limit = 5

        val response = runCatching {
            sdkManager.getNowAttachmentService()?.attachmentMetadata(Filter(filterQuery), limit)?.execute()
        }

        if (response.isSuccess) {
            val attachmentMetadataList = response.getOrNull()?.body
        } else {
            Log.e("NowSDK", "result not successful")
        }
    }

## 첨부 파일 메타데이터 페이지 매김 {#mobsdk-and-retrieve_attach_metadata__section_stt_34w_3qb}

NowAttachmentService 메서드를 사용하여 하나 이상의 첨부 파일에 대한 첨부 파일 메타데이터를 다운로드할 수 있습니다. 여러 첨부 파일에서 메타데이터를 다운로드할 때 반환될 수 있는 잠재적으로 많은 양의 데이터를 쉽게 반복할 수 있는 Paginator 개체를 반환하는 메서드를 사용할 [NowAttachmentService - attachmentMetadataPaginator(filter: filter? = null, limit: Int? = null)](https://servicenow-prod.fluidtopics.net/CpbdypUWKnerHQystjloBQ#NAttServ-attachMetadataPaginat_S_I "지정된 기준을 충족하는 모든 첨부 파일에 대한 메타데이터를 검색하고 반환된 메타데이터의 페이지를 반복하기 위한 페이지 매김기를 만듭니다.") 수 있습니다.  
그런 다음 Paginator 메서드를 사용하고 observe() 콜백에서 응답을 수신하여 반환된 메타데이터를 반복할 수 있습니다.

     suspend fun createAttachmentMetadataPaginator() {
      val filterQuery: String = "content_type=text/plain"
      val filter = filterQuery.let(::Filter)
      val limit = 10

      val paginator = sdkmanager.getNowAttachmentService()?.attachmentMetadataPaginator(filter, limit)
        ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {
          override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {
            // Handle response
          }

          override fun onFailure(e: NowDataError) {
            // Handle error
          }

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

      // Use paginator operators to navigate. Example
      while (paginator.hasNext() && !paginator.isBusy()) {
        paginator.next()
      }
    }

반환된 Paginator 객체는 반환된 레코드를 페이징할 수 있는 다음과 같은 메서드를 제공합니다. 먼저 observe() 함수를 호출하여 Paginator의 콜백을 설정해야 합니다.

* 첫 번째()
* hasNext()를 호출합니다.
* hasPrevious (이전에는)
* isbusy 님
* 마지막()
* 다음()
* 관찰()
* 이전()
* 재설정()

{#mobsdk-and-retrieve_attach_metadata__ul_pyb_2w3_3qb}  
주:  
일부 Paginator 메서드는 가져올 페이지가 더 이상 없는 경우와 같이 예외를 발생시킬 수 있습니다.

