CoreBase makes file uploads easy. You can upload files directly from the browser to your storage buckets.
Buckets
Files live inside buckets — create one before uploading to it.
await corebase.storage.createBucket({
name: 'avatars',
public: true,
allowedMimeTypes: ['image/png', 'image/jpeg'],
fileSizeLimit: 5 * 1024 * 1024, // 5MB
});
const { data: buckets } = await corebase.storage.listBuckets();
const { data } = await corebase.storage.getBucket('avatars'); // bucket + its files
A bucket must be empty before you can delete it — use emptyBucket() first, or
deleteBucket() will fail.
Upload a File
Get the file from an input
Use a standard HTML file input to select a file from the user’s device.// Example: <input type="file" id="fileInput" />
const fileInput = document.getElementById('fileInput') as HTMLInputElement;
const file = fileInput.files?.[0];
Upload the file to a bucket
Call the upload method with the selected file and the bucket name.if (file) {
const { data, error } = await corebase.storage.upload(file, 'avatars');
if (error) {
console.error('Upload failed:', error);
} else {
console.log('Success! File uploaded.');
console.log('File Key:', data.key);
console.log('File URL:', data.url);
}
}
List & Delete Files
const { data: files } = await corebase.storage.listFiles({ bucket: 'avatars' });
// Download the raw bytes (e.g. to re-upload elsewhere, or process server-side)
const { data: blob } = await corebase.storage.downloadFile(files.files[0].id);
await corebase.storage.deleteFile(files.files[0].id);
For displaying a file (e.g. in an <img> tag), use the url returned from upload()
or found on each file record — downloadFile() is for when you need the raw bytes in code.