Image Optimization
Reduce image size without losing visible quality. Bucket can optimize images during upload or process already stored images on demand.
Optimize during upload
Add ?optimize=true to the upload URL. The server compresses the image before storing it and returns the final path and size.
typescript
const formData = new FormData();
formData.append('file', file);
const response = await fetch(
`https://bucket.dveloxsoft.com/api/files/${containerSlug}/${encodeURIComponent(path)}?optimize=true`,
{
method: 'POST',
headers: {
'Authorization': 'ApiKey <api_key>'
},
body: formData
}
);
if (!response.ok) {
const error = await response.json();
throw new Error(error.message || 'Optimized upload failed');
}
const result = await response.json();
console.log('Optimized upload:', result.path, result.size, 'bytes'); Optimize an existing image
Send POST /files/:containerSlug/optimize with the image path. The server overwrites the file with a compressed version.
typescript
const response = await fetch(
`https://bucket.dveloxsoft.com/api/files/${containerSlug}/optimize`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'ApiKey <api_key>'
},
body: JSON.stringify({
path: 'path/to/image.jpg'
})
}
);
const result = await response.json();
console.log('Optimized image:', result.path, result.size, 'bytes');