Skip to content
Release: Australia · Updated: 2026-03-12 · Official documentation · View source

NowAttachmentMetadata structure- iOS

The NowAttachmentMetadata structure provides functions that enable you to encode and manage attachment metadata.

NameTypeDescription
averageImageColorStringMost dominant color in the associated image.
chunkSizeInBytesIntegerSize of the chunk.Unit: Bytes
compressed​Size​InBytesIntegerCompressed size of the attachment.Unit: Bytes
createdDateDate on which the attachment was created.
createdByStringEntity that created the attachment.
downloadURLURL of the attachment on the ServiceNow instance.
fileNameStringName of the attachment file.
hashStringExpected SHA256 digest for the attachment.A downloaded attachment is validated by comparing its computed digest to this SHA256 digest.
imageHeightIntegerHeight of image.Unit: Pixels
imageWidthIntegerWidth of image.Unit: Pixels
isCompressedBooleanFlag that indicates whether the attachment file is compressed.Possible values: - true: Attachment is compressed. - false: Attachment in not compressed.
mimeTypeStringAttachment MIME type.
modificationCountIntegerNumber of times that the attachment was modified.
sizeInBytesIntegerSize of the attachment.Unit: Bytes
sourceSysIdStringSys\_id of the attachment file.
sourceTableNameStringName of the source table in which the attachment resides.
state Availability state, such as conditionally, unavailable, available, and pending.
sysIdStringUnique 32-character Globally Unique ID \(GUID\), that identifies each record in a ServiceNow instance.
tagsStringList of tags associated with the attachment.
updatedDateDate on which the attachment was last modified.
updatedByStringEntity that updated the attachment.

Parent Topic:Mobile SDK - iOS

NowAttachmentMetadata - encode(to encoder: Encoder)

Encodes the current object value into data using the specified encoder.

If the object fails to be encoded into data, the encoder encodes an empty keyed container in its place. This function also throws an error if any values are invalid for the specified encoder's format.

NameTypeDescription
to encoderEncoderEncoder that defines the structure of the encoded output.
TypeDescription
None 

The following code example shows how to call this function.

let query = "active=true^short_descriptionLIKEbroken"
let filter = Filter(query: query)
metadataPublisher(filter: filter, limit: 1)
private func metadataPublisher(filter: Filter?, limit: Int?) {
  let publisher = attachmentService.attachmentMetadata(filter: filter, limit: limit)
  publisher
  .receive(on: DispatchQueue.main)
  .encode(encoder: JSONEncoder())
  .sink { [weak self] completion in
    if case let .failure(error) = completion {
      // attachment published failed, return NowDataError
    }
  } receiveValue: { [weak self] (data) in
    // Attachment published successful, return data
  }
  .store(in: &subscriptions)
}

NowAttachmentMetadata - init(from decoder: Decoder)

Creates a new NowAttachmentMetadata instance by decoding data into an object from the specified decoder.

This method throws an error if reading from the decoder fails or if the data read is corrupt or otherwise invalid.

NameTypeDescription
decoderDecoderDecoder to read data from.
TypeDescription
None 

The following code example shows how to call this function.

guard 
  let metadataHeader = response.httpResponse?.value(forHTTPHeaderField: NowAttachment.attachmentMetadataHeaderKey),
  let metadataHeaderData = metadataHeader.data(using: .utf8) else {
    throw NowDataError.missingAttachmentMetadata
  }

let metadata = try coder.decode(NowAttachmentMetadata.self, from: metadataHeaderData)
let attachment = NowAttachment(metadata: metadata, data: response.data)