Tệp Đính Kèm
Tải tệp lên AgentSend và đính kèm vào tin nhắn gửi đi. Lấy URL presigned để tải xuống hoặc chia sẻ nội dung tệp đính kèm.
Tải tệp đính kèm lên trước, sau đó tham chiếu id của nó trong trường attachmentIds khi gửi tin nhắn. Tệp đính kèm được lưu trữ an toàn và truy cập được qua URL presigned có giới hạn thời gian.
Tải Lên Tệp Đính Kèm
Tải một tệp lên và trả về đối tượng Attachment. Sử dụng id được trả về để đính kèm tệp vào tin nhắn. Yêu cầu phải dùng mã hóa multipart/form-data.
Nội Dung Yêu Cầu
Content-Type: multipart/form-data
| Trường | Kiểu | Mô tả |
|---|---|---|
file bắt buộc |
file | The file to upload. The filename and content type are inferred from the uploaded part. |
Example Request
curl -X POST https://api.agentsend.io/attachments \ -H "x-api-key: $AGENTSEND_API_KEY" \ -F "file=@/path/to/report.pdf"
const form = new FormData(); form.append("file", fileBlob, "report.pdf"); const res = await fetch("https://api.agentsend.io/attachments", { method: "POST", headers: { "x-api-key": process.env.AGENTSEND_API_KEY }, body: form, }); const attachment = await res.json(); console.log(attachment.id); // use this id when sending a message
Response — 201 Created
{
"id": "att_01j9zxkp4qbc7n3m8td5e6fvg2",
"filename": "report.pdf",
"contentType": "application/pdf",
"size": 204800,
"url": "https://storage.agentsend.io/att_01j9zxkp4qbc7n3m8td5e6fvg2/report.pdf?token=...",
"createdAt": "2025-11-10T08:15:00Z"
}Lấy Tệp Đính Kèm
Retrieves metadata and a short-lived presigned download URL for an attachment. Use the url field to download or display the file content directly.
Path Parameters
| Tham số | Kiểu | Mô tả |
|---|---|---|
id bắt buộc |
uuid | The ID of the attachment to retrieve. |
Example Request
curl https://api.agentsend.io/attachments/att_01j9zxkp4qbc7n3m8td5e6fvg2 \
-H "x-api-key: $AGENTSEND_API_KEY"Response — 200 OK
{
"id": "att_01j9zxkp4qbc7n3m8td5e6fvg2",
"filename": "report.pdf",
"contentType": "application/pdf",
"size": 204800,
"url": "https://storage.agentsend.io/att_01j9zxkp4qbc7n3m8td5e6fvg2/report.pdf?token=...",
"createdAt": "2025-11-10T08:15:00Z"
}Attachment Object
| Trường | Kiểu | Mô tả |
|---|---|---|
id |
string | Định danh duy nhất của attachment. |
filename |
string | Original filename as provided at upload time. |
contentType |
string | MIME type of the file (e.g. application/pdf, image/png). |
size |
number | File size in bytes. |
url |
string | Presigned URL to download the file. This URL is time-limited; fetch a fresh one by calling this endpoint again if it expires. |
createdAt |
string | Dấu thời gian ISO 8601 when the attachment was uploaded. |
Presigned URLs expire after a short period. If you need to share or re-download an attachment, call GET /attachments/{id} again to obtain a fresh URL.