Download a Document
Retrieve a presigned S3 URL to download your document. The URL is temporary and secure, expiring after the specified duration.
Path Parameters
The unique identifier of the document to download (UUID)
Query Parameters
Number of seconds until the download URL expires (1-86400). Default is 3600 (1
hour).
Response
Presigned S3 URL for downloading the document
Number of seconds until the URL expires
Original filename of the document
Code Examples
const docId = "a1b2c3d4-e5f6-7890-abcd-ef1234567890";
const response = await fetch(
`https://api.agentoffice.dev/v1/documents/${docId}?expiresIn=3600`,
{
headers: {
Authorization: "Bearer YOUR_API_KEY",
},
}
);
const data = await response.json();
// Download the file
const downloadResponse = await fetch(data.downloadUrl);
const blob = await downloadResponse.blob();
// Create download link
const url = window.URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = data.filename;
a.click();
Example Response
{
"docId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"downloadUrl": "https://s3.amazonaws.com/bucket/document.docx?X-Amz-Algorithm=...",
"expiresIn": 3600,
"filename": "report.docx"
}
Complete Workflow Example
Here’s a complete example showing upload, edit, and download:
import { v4 as uuidv4 } from "uuid";
const API_KEY = "YOUR_API_KEY";
const BASE_URL = "https://api.agentoffice.dev";
async function processDocument(file) {
// 1. Upload document
const formData = new FormData();
formData.append("file", file);
const uploadResponse = await fetch(`${BASE_URL}/v1/documents/`, {
method: "POST",
headers: { Authorization: `Bearer ${API_KEY}` },
body: formData,
});
const { docId } = await uploadResponse.json();
console.log("Uploaded document:", docId);
// 2. Apply edit
const editResponse = await fetch(`${BASE_URL}/v1/documents/${docId}/edits`, {
method: "POST",
headers: {
Authorization: `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
editUid: uuidv4(),
editInstructions: "Update all dates to 2024",
}),
});
const editResult = await editResponse.json();
console.log("Edit applied:", editResult.editApplied);
// 3. Download edited document
const downloadResponse = await fetch(`${BASE_URL}/v1/documents/${docId}`, {
headers: { Authorization: `Bearer ${API_KEY}` },
});
const { downloadUrl, filename } = await downloadResponse.json();
// Download the file
const fileResponse = await fetch(downloadUrl);
const blob = await fileResponse.blob();
// Trigger browser download
const url = window.URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = filename;
a.click();
console.log("Downloaded:", filename);
}
Presigned URL Security
The presigned URL allows anyone with the link to download the document. Keep
URLs private and don’t share them publicly.
URL Expiration
- Presigned URLs expire after the specified duration (default 1 hour)
- You can generate a new URL at any time by calling the endpoint again
- Expired URLs will return a 403 Forbidden error
Best Practices
Use shorter expiration times (e.g., 300 seconds) for sensitive documents
Generate a new URL for each download to maintain security
Download files programmatically instead of exposing URLs to end users
Error Responses
{
"detail": "Document not found or has expired"
}
Documents are automatically deleted after their TTL expires. Make sure to
download important documents before they expire.