Skip to main content
Version: v2.0

Attachment file overview

The Attachment File API lets you interact with the raw binary content of file attachments. Unlike the base Attachment API which handles metadata (like filenames and sizes), the File sub-module handles the actual upload and download of file data.

Commonly used for:

  • Uploading a new file and attaching it to a specific record.
  • Downloading the content of an existing attachment by its sys_id.

Basic usage

Uploading a file

To upload a file, you specify the target table and record ID, along with the desired filename and the raw data.

// Build media type
dataContentType := "text/plain"
data := []byte("this is example data")
media := attachmentapi.NewMedia(dataContentType, data)

createFileTableSysId := "{SysID}"
createFileTableName := "{TableName}"
createFileFileName := "example.txt"

createFileConfig := &attachmentapi.AttachmentFileRequestBuilderPostRequestConfiguration{
QueryParameters: &attachmentapi.AttachmentFileRequestBuilderPostQueryParameters{
TableSysID: &createFileTableSysId, // required
TableName: &createFileTableName, // required
FileName: &createFileFileName, // required
},
// Optional configurations
}

createFileResponse, err := client.Now().Attachment().File().Post(context.Background(), media, createFileConfig)
if err != nil {
log.Fatal(err)
}

Downloading a file

To download a file, you use the ByID method with the attachment's sys_id and then access the File() sub-module.

fileGetConfig := &attachmentapi.AttachmentItemFileRequestBuilderGetRequestConfiguration{
// Optional configurations
}

fileGetResponse, err := client.Now().Attachment().ByID("{SysID}").File().Get(context.Background(), fileGetConfig)
if err != nil {
log.Fatal(err)
}

Available operations

Was this page helpful?