Skip to content
v2.7

Files

Upload, download, display and generate thumbnails of files.

arquivos.ts
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);
  • Upload: createFile takes a File (from an <input type="file"> or from drag and drop). Large files are uploaded in chunks automatically; onProgress reports progress.
  • URLs: getFileView (display), getFileDownload (download with the original name) and getFilePreview (image thumbnail: width, height, quality, format, borders) only build the address. A file with public read access (Role.any()) opens anywhere; to send a private file to someone outside your project, use a share link.
  • Folders: the folder parameter (for example, photos/2026) organizes files inside the bucket.
arquivo-servidor.ts
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);

In @owbase/node, InputFile (from @owbase/node/file) reads from disk (fromPath), from a Buffer (fromBuffer) or from text (fromPlainText). There, getFileView and getFileDownload return the content (ArrayBuffer), not the URL.

The maximum size is the bucket’s, up to 30 MB per file. A larger file returns storage_invalid_file_size; an extension outside the list returns storage_file_type_unsupported.

Was this page helpful?