Attachment uploads
You can send attachments as files[n] parts in a multipart message, or upload them first and attach them by their upload key (upload_filename).
- Request an upload plan.
- Send the bytes to its upload URLs.
- Complete the upload if it is multipart.
- Attach the upload by its key to a new message, an edited message or a new thread.
Uploading first needs presigned_attachment_uploads set to true in instance features. When it is off, the plan and completion requests return 403 FEATURE_TEMPORARILY_DISABLED, and you send files in a multipart message.
Choose how to upload
Заголовок раздела «Choose how to upload»Each file can be up to the max_attachment_file_size limit. A bot gets the lower of that limit and max_bot_attachment_file_size, which is 52428800 bytes (50 MiB) by default. On Squad’s own instance, an account without premium has a max_attachment_file_size of 26214400 bytes (25 MiB) by default, and a bot gets 25 MiB there. A self-hosted instance allows 500 MiB by default, and a bot gets 50 MiB.
In a multipart message, Squad checks each file part while it arrives. When a part goes over the limit, the request fails with 400 FILE_SIZE_TOO_LARGE. When Content-Length is larger than every allowed file plus the rest of the message, the request fails with 413 FILE_SIZE_TOO_LARGE and Squad saves none of it. In both cases Squad gets up to 64 MiB of the rest of the body before it responds. If more is left, it responds right away and closes the connection, and some HTTP clients then report a connection reset and never show the response. Check each file’s size against the limit before you send it.
When the instance is already streaming many files, a file part can wait up to 10 seconds and then fail with 503 and a Retry-After header. A multipart request also has to finish within the instance’s request timeout, which is 120 seconds by default.
The web and desktop apps upload files first if the instance has presigned_attachment_uploads on, and bots should do so for large files. The bytes go directly to storage or the upload relay, in one request or in parts for a file above 10 MiB. The API request timeout does not apply to them.
Request an upload plan
Заголовок раздела «Request an upload plan»Call Request attachment upload URLs with up to 10 files, each with its exact byte count.
Each file in the plan has an upload_mode that decides which fields it gets.
| Value | When | Added fields |
|---|---|---|
| singlepart | A file_size of at most 10485760 bytes (10 MiB) | upload_url |
| multipart | A file_size above 10485760 bytes | upload_id, part_size and parts |
Each parts entry has a part_number starting at 1 and its own upload_url.
Upload the bytes
Заголовок раздела «Upload the bytes»Send a PUT to each upload_url exactly as returned, with no Authorization header. Squad picks content_type from the file name, and a singlepart upload must send the whole file with it as Content-Type. A multipart upload sends each part to its own URL, with exactly part_size bytes in every part except the last.
An upload URL points to storage or to the upload relay, and it expires after the time below.
| Upload URL | Lifetime |
|---|---|
| Storage, singlepart | 5 minutes |
| Storage, multipart part | 1 hour |
| Upload relay | 15 minutes by default, and the instance can change it |
Keep upload URLs out of logs. Anyone who has one can upload to it until it expires. When a URL expires, request a new upload plan and then send the whole file over again.
Complete a multipart upload
Заголовок раздела «Complete a multipart upload»After every part has uploaded, call Complete attachment upload with the upload_filename and upload_id of up to 10 uploads. Squad checks permissions and the file size limit again. If completion fails because no parts arrived, the parts are too large or storage can’t finish the upload, Squad cancels it and you need a new plan.
Attach the upload
Заголовок раздела «Attach the upload»Put the upload_filename in a pre-uploaded attachment for Create message, Modify message or Start thread in a forum or media channel.
An upload key works once, for the user and channel that requested it. Using a key that belongs to someone else, was requested for another channel or was already used returns 400 INVALID_FORM_BODY with UPLOADED_ATTACHMENT_NOT_FOUND.
A key whose bytes never uploaded returns the same error with FILE_NOT_FOUND.
Stream previews
Заголовок раздела «Stream previews»A stream preview is a JPEG of at most 1000000 bytes that shows for a voice stream. Upload it with either of these Streams API endpoints.
- Upload stream preview takes the image as canonical base64 in JSON, using the standard alphabet with padding. Any other encoding returns 400
INVALID_STREAM_THUMBNAIL_PAYLOAD. - Create stream preview upload URL returns a URL. Send the JPEG to it with
PUTand the returnedcontent_typebeforeexpires_at, and keep it at or undermax_bytes.
A preview expires one day after you upload it or request its upload URL, and after that Get stream preview returns 404 Not Found.