Presigned URLs allow you to grant temporary access for uploading files directly to your bucket without exposing your API credentials to the client.
Benefits
- Security: Your API key remains server-side; the client only receives a temporary URL.
- Performance: Files transfer directly to the storage, reducing load on your backend.
- Control: URLs expire automatically and are strictly scoped to the specific file path.
Bearer token for authentication (e.g., Bearer <your-api-key>).
Query Parameters
The name of the target bucket.
The destination path for the file (e.g., uploads/avatar.jpg).
Expiration time in seconds (max: 3600).
Response
Indicates if the generation was successful.
The URL to use for the PUT request.
The specific key (path) for the file.
Duration in seconds until expiration.
ISO timestamp of when the URL will expire.
Usage Example
1. Generate the URL (Server-side)
First, your backend requests a presigned URL.
curl -X GET https://cdn.sacul.cloud/my-bucket/presigned/users/123/avatar.png?expiresIn=300 \
-H "Authorization: Bearer <your-api-key>"
2. Upload the File (Client-side)
Once your frontend receives the presignedUrl, use a PUT request to upload the file.
// Example: Uploading a file from an input element
const uploadFile = async (file) => {
// 1. Fetch the presigned URL from your backend (which calls the sCloud API)
const response = await fetch('/api/get-upload-url');
const { presignedUrl } = await response.json();
// 2. Direct upload to sCloud using the presigned URL
await fetch(presignedUrl, {
method: 'PUT',
body: file,
headers: {
'Content-Type': file.type // Ensure Content-Type matches the file
}
});
};