Storage
Upload
Section titled “Upload”import com.bunbase.sdk.UploadOptions
val bytes: ByteArray = /* file content */
val file = client.files.upload( data = bytes, filename = "photo.jpg", mimeType = "image/jpeg",)println(file.id)println(file.key)Upload with progress
Section titled “Upload with progress”val file = client.files.upload( data = bytes, filename = "video.mp4", mimeType = "video/mp4", options = UploadOptions( bucket = "media", isPublic = true, onProgress = { written, total -> val pct = (written * 100 / total).toInt() // Update progress bar (dispatch to main thread for UI) }, ),)Associate with a record
Section titled “Associate with a record”val file = client.files.upload( data = bytes, filename = "avatar.jpg", mimeType = "image/jpeg", options = UploadOptions( collection = "users", recordId = userId, bucket = "avatars", ),)Download
Section titled “Download”val bytes = client.files.download(file.id)// e.g. save to disk or display as bitmapPublic URL
Section titled “Public URL”// For public files only — no authentication requiredval url = client.files.publicUrl(file.id, filename = "photo.jpg")Signed URL (private files)
Section titled “Signed URL (private files)”// Default 1-hour expiryval url = client.files.signedUrl(file.id)
// Custom expiry (seconds)val url = client.files.signedUrl(file.id, expiresIn = 7200)Pre-signed upload (S3 / large files)
Section titled “Pre-signed upload (S3 / large files)”Get a pre-signed PUT URL and upload directly to the storage backend — bypasses BunBase for the data transfer.
val result = client.files.signedUpload( filename = "large-video.mp4", contentType = "video/mp4", options = UploadOptions(bucket = "videos", isPublic = false), expiresIn = 3600,)
// Upload directly to result.url using any HTTP client:// PUT result.url with Content-Type: video/mp4val files = client.files.list(limit = 50, page = 1)files.forEach { println("${it.filename} — ${it.size} bytes") }Delete
Section titled “Delete”client.files.delete(file.id)