Skip to content
BunBase BunBase BunBase Docs Alpha v0.1.0

Storage

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)
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)
},
),
)
val file = client.files.upload(
data = bytes,
filename = "avatar.jpg",
mimeType = "image/jpeg",
options = UploadOptions(
collection = "users",
recordId = userId,
bucket = "avatars",
),
)
val bytes = client.files.download(file.id)
// e.g. save to disk or display as bitmap
// For public files only — no authentication required
val url = client.files.publicUrl(file.id, filename = "photo.jpg")
// Default 1-hour expiry
val url = client.files.signedUrl(file.id)
// Custom expiry (seconds)
val url = client.files.signedUrl(file.id, expiresIn = 7200)

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/mp4
val files = client.files.list(limit = 50, page = 1)
files.forEach { println("${it.filename} — ${it.size} bytes") }
client.files.delete(file.id)