code
DveloxSoft Bucket Guías de integración para desarrolladores

Optimización de imágenes

Reduce el tamaño de las imágenes sin perder calidad visible. Bucket puede optimizar imágenes durante la carga o procesar imágenes ya almacenadas bajo demanda.

Optimizar durante la carga

Agrega ?optimize=true a la URL de carga. El servidor comprime la imagen antes de almacenarla y devuelve la ruta y el tamaño finales.

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');

Optimizar una imagen existente

Envía POST /files/:containerSlug/optimize con la ruta de la imagen. El servidor sobrescribe el archivo con una versión comprimida.

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');