FesaComponents
Más módulos

Storage

Cloudflare R2 detrás del puerto IStorageService, con URLs prefirmadas.

import { R2StorageService } from "@fesa/components/storage";
import type { IStorageService } from "@fesa/components/utils";

El adapter R2/S3 unificado (antes existían tres variantes, dos con contratos incompatibles entre sí).

API

MétodoQué hace
upload(key, body, contentType)Sube un objeto
download(key)Descarga un objeto
getSignedUrl(key, expiresIn?)URL firmada de lectura
getUploadUrl(key, contentType, expiresIn?)URL prefirmada de subida — el navegador sube directo a R2
delete(key)Elimina
exists(key)Comprueba existencia

Flujo de subida directa (presign)

// 1. Server action: firmar
const storage = new R2StorageService();
const { url, publicUrl } = await storage.getUploadUrl(key, file.type);

// 2. Cliente: subir directo a R2 (sin pasar por tu servidor)
await fetch(url, { method: "PUT", body: file, headers: { "Content-Type": file.type } });

// 3. Persistir publicUrl

Validar SIEMPRE tipo y tamaño en la action que firma — la URL prefirmada es un cheque en blanco por expiresIn segundos.

Configuración

Variables de entorno: R2_ACCOUNT_ID, R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY, R2_BUCKET_NAME, R2_PUBLIC_URL.

Peers opcionales: @aws-sdk/client-s3 y @aws-sdk/s3-request-presigner — solo los instala quien importa este módulo.

Siguiente ola: ./uploads

El pipeline completo (presign con guard multi-tenant + prepareImage en canvas + commit tmp→final + dropzone) se unificará desde las tres variantes de FesaStore, Fesa ID y transfer.

En esta pagina