im.attachments uploads file bytes to the server, reads attachment metadata, and downloads attachments in chunks. Sending an attachment message is a two-step flow: upload the file to get an attachment GUID, then pass that GUID to the messages API.
Message sends accept server attachment GUIDs. They do not accept local file paths.
What You Can Do
| Need | Use this when |
|---|---|
| Upload a regular attachment | You are sending an image, video, audio file, document, or archive |
| Upload a Live Photo | You have a HEIC/HEIF still image plus the matching MOV companion video |
| Read metadata | You need the file name, MIME type, size, or transfer state |
| Stream a download | You need the attachment bytes; Live Photos may include a companion stream |
Upload an Attachment
A regular attachment needs two fields:fileName and data. After upload, send uploaded.attachment.guid.
upload(...) returns UploadAttachmentResult. For a regular attachment, use the attachment field:
| Input | Rule |
|---|---|
fileName | Display file name. Include an extension when possible. The server sanitizes path characters; an empty value falls back to attachment. |
data | Raw file bytes. Must not be empty. |
fileName extension. Files without an extension can still upload, but unknown types may be labeled application/octet-stream / public.data, which usually gives recipients a worse preview. Keep extensions for documents, archives, and Office files.
Each uploaded file is limited to 100 MiB by default.
Common Formats
The SDK uploads raw bytes and the server stores them as-is. Messages.app and Apple’s delivery path decide how the recipient sees the file: inline preview, file attachment, transcoded media, or an iCloud link.| Type | Common formats | Notes |
|---|---|---|
| Images | HEIC, HEIF, JPEG, PNG, GIF, TIFF, BMP, WebP, AVIF, SVG | Non-Apple environments may need conversion |
| Video | MOV, MP4, WebM | Apple may transcode depending on recipient device support |
| Audio | M4A, MP3, WAV, AIFF, FLAC, CAF | Pass isAudioMessage: true to sendAttachment(...) for the audio-message UI |
| Documents | PDF, DOCX, XLSX, PPTX, TXT, CSV, JSON, HTML, XML, RTF | Preview behavior depends on the recipient device |
| Archives | ZIP, TAR, GZ, BZ2, XZ | Usually delivered as file attachments |
Upload a Live Photo
A Live Photo is a paired upload: the primary file is a HEIC/HEIF image, andcompanion.data is the matching QuickTime .MOV video. When sending, still pass only livePhoto.attachment.guid.
UploadAttachmentResult includes both attachment and companion:
100 MiB upload limit.
Get Metadata
You do not needget(...) before sending an attachment. Use it when you need to inspect attachment state, display file information, or confirm that a file is ready before downloading.
AttachmentInfo. Use transferState to decide whether the attachment is ready to download. Missing or unresolvable attachments throw NotFoundError.
transferState can be:
| Value | Meaning |
|---|---|
"pending" | Waiting to transfer |
"transferring" | Transfer in progress |
"failed" | Transfer failed |
"finished" | Ready |
"unknown" | Server could not classify the state |
Stream Downloads
Before downloading, check thattransferState === "finished" when you can. Otherwise the server may throw attachmentNotReady.
header frame first, followed by data chunks. Regular attachments only emit primaryChunk; Live Photos may also emit companionChunk.
frame.type | Meaning | Extra fields |
|---|---|---|
header | First frame with metadata | info, companionInfo? |
primaryChunk | Chunk from the primary file | data |
companionChunk | Chunk from the Live Photo companion video | data |
for await loop cancels the download.
| Case | Result |
|---|---|
| Attachment does not exist | Throws NotFoundError |
| Attachment is not ready | Throws ValidationError, with error.code === ErrorCode.attachmentNotReady |
header.companionInfo is present | This is a Live Photo download; later frames may include companionChunk |
get(...) until transferState becomes "finished", then call downloadStream(...).
Minimal save-to-file example:
Next Steps
- Messages — send attachment messages with attachment GUIDs
- Error Handling — handle
NotFoundError,ValidationError, andattachmentNotReady - Chats — create a chat and get
chat.guid