Files
Generate a presigned PUT URL for direct browser upload
Issue a presigned PUT URL for clients to upload directly to object storage. The server stores the issued key with expiry and RBAC is enforced. PUT (not POST) is used because Cloudflare R2 does not implement the S3 POST Object API. The client must PUT the file body to `url` with the exact `headers` returned (a Content-Type mismatch fails with SignatureDoesNotMatch). `maxFileUploadBytes` is enforced server-side by `/api/files/upload/confirm` after the upload, not by the presigned URL itself.
/api/files/upload/presignedSDK setup
Create a client and set credentials (JWT and/or API key) before calling the API. Match the authentication type shown above.
import { Configuration, FilesApi } from 'mudbase-sdk';
const configuration = new Configuration({
basePath: 'https://cloud.mudbase.dev',
apiKey: 'sk_live_mudbase_doc_Xk9mP2qR7vN4wL8jH3tY6uE',
accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c3JfbW9yZ2FuX2RlIiwiZW1haWwiOiJtb3JnYW4uY2hlbkBub3J0aHdpbmQuZGV2IiwiZXhwIjoxODI1MTI5NjAwfQ.doc_preview_sig',
});
// This endpoint accepts either credential — apiKey or accessToken alone is enough.
const files = new FilesApi(configuration);import { Configuration, FilesApi } from 'mudbase-sdk';
const configuration = new Configuration({
basePath: 'https://cloud.mudbase.dev',
apiKey: 'sk_live_mudbase_doc_Xk9mP2qR7vN4wL8jH3tY6uE',
accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c3JfbW9yZ2FuX2RlIiwiZW1haWwiOiJtb3JnYW4uY2hlbkBub3J0aHdpbmQuZGV2IiwiZXhwIjoxODI1MTI5NjAwfQ.doc_preview_sig',
});
// This endpoint accepts either credential — apiKey or accessToken alone is enough.
const files = new FilesApi(configuration);Example request
Call this endpoint using the client from SDK setup. Use View HTTP for a raw cURL example.
const { data: result } = await files.generatePresignedUpload(
{
projectId: "proj_X7ESx1DiGuki",
bucket: "pixel parse",
originalName: "Icie Padberg",
contentType: "panel override",
isPublic: true
}
);const { data: result } = await files.generatePresignedUpload(
{
projectId: "proj_X7ESx1DiGuki",
bucket: "pixel parse",
originalName: "Icie Padberg",
contentType: "panel override",
isPublic: true
}
);Playground
liveTest this endpoint with your own credentials. Your requests will be sent to the live API.
No Request Yet
Send a request to see the full inspector
Authentication
Authorization: Bearer YOUR_TOKEN for user context, or X-API-Key: YOUR_KEY for server-to-server. View authentication guide →Include your JWT in the Authorization: Bearer YOUR_TOKEN header (user-facing apps, RBAC). View authentication guide →Include your API key in the X-API-Key: YOUR_KEY header (server-to-server, SDKs). View authentication guide →Request Body
{
"projectId": "proj_qh5hFHNT70YZ",
"bucket": "interface calculate",
"originalName": "Ms. Freda Romaguera III",
"contentType": "sensor program",
"isPublic": false
}{
"projectId": "proj_qh5hFHNT70YZ",
"bucket": "interface calculate",
"originalName": "Ms. Freda Romaguera III",
"contentType": "sensor program",
"isPublic": false
}Responses
{
"key": "65a1b2c3d4e5f6789012345a/default/abcd-1234-invoice.pdf",
"url": "https://my-bucket.r2.cloudflarestorage.com/65a1b2c3d4e5f6789012345a/default/abcd-1234-invoice.pdf?X-Amz-Signature=...",
"method": "PUT",
"headers": {
"Content-Type": "application/pdf"
},
"expiresIn": 3600,
"maxFileUploadBytes": 52428800
}{
"key": "65a1b2c3d4e5f6789012345a/default/abcd-1234-invoice.pdf",
"url": "https://my-bucket.r2.cloudflarestorage.com/65a1b2c3d4e5f6789012345a/default/abcd-1234-invoice.pdf?X-Amz-Signature=...",
"method": "PUT",
"headers": {
"Content-Type": "application/pdf"
},
"expiresIn": 3600,
"maxFileUploadBytes": 52428800
}Errors
| Code | Meaning |
|---|---|
400 | — |
401 | — |
403 | — |
429 | — |
500 | — |