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
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:
The file extension is not strictly required. The server first tries to detect MIME / UTI from the bytes, then falls back to the
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.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:
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.
for await loop cancels the download.
If an attachment is not ready, poll
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