En el navegador
Sección titulada «En el navegador»import { ID, ImageFormat, Permission, Role, Storage } from '@owbase/web';import { client } from './client';
const storage = new Storage(client);const input = document.querySelector<HTMLInputElement>('#photo')!;
// Upload (large files go in chunks; onProgress shows the progress).const file = await storage.createFile({ bucketId: 'photos', fileId: ID.unique(), file: input.files![0], permissions: [Permission.read(Role.any())], onProgress: (p) => console.log(`${Math.round(p.progress)}%`),});
// Ready-made URLs for <img>, <a download>, etc. (they make no request: they only build the address).const view = storage.getFileView({ bucketId: 'photos', fileId: file.$id });const download = storage.getFileDownload({ bucketId: 'photos', fileId: file.$id });const thumbnail = storage.getFilePreview({ bucketId: 'photos', fileId: file.$id, width: 320, height: 320, output: ImageFormat.Webp });console.log(view, download, thumbnail);- Subida:
createFilerecibe unFile(de un<input type="file">o de arrastrar y soltar). Los archivos grandes se envían en partes automáticamente;onProgressinforma el avance. - URLs:
getFileView(mostrar),getFileDownload(descargar con el nombre original) ygetFilePreview(miniatura de imagen: ancho, alto, calidad, formato, bordes) solo arman la dirección. Un archivo con lectura pública (Role.any()) se abre en cualquier lugar; para enviar un archivo privado a alguien de fuera, usa un enlace para compartir. - Carpetas: el parámetro
folder(por ejemplo,fotos/2026) organiza los archivos dentro del bucket.
En el servidor
Sección titulada «En el servidor»import { ID, Storage } from '@owbase/node';import { InputFile } from '@owbase/node/file';import { client } from './client';
// The key needs the files.write scope.const storage = new Storage(client);
const invoice = await storage.createFile({ bucketId: 'invoices', fileId: ID.unique(), file: InputFile.fromPath('./invoice.pdf', 'invoice.pdf') });console.log(invoice.$id, invoice.sizeOriginal);En @owbase/node, InputFile (de @owbase/node/file) lee del disco (fromPath), de un Buffer (fromBuffer) o de texto (fromPlainText). Allí, getFileView y getFileDownload devuelven el contenido (ArrayBuffer), no la URL.
Límites
Sección titulada «Límites»El tamaño máximo es el del bucket, hasta 30 MB por archivo. Un archivo mayor da storage_invalid_file_size; una extensión fuera de la lista da storage_file_type_unsupported.
¿Te ayudó esta página?Gracias por tu opinión.