In the browser
Section titled “In the browser”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:
createFiletakes aFile(from an<input type="file">or from drag and drop). Large files are uploaded in chunks automatically;onProgressreports progress. - URLs:
getFileView(display),getFileDownload(download with the original name) andgetFilePreview(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
folderparameter (for example,photos/2026) organizes files inside the bucket.
On the server
Section titled “On the server”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.
Limits
Section titled “Limits”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?Thanks for your feedback.