Kotlin: Download a file

Parameters

Examples

Download file from non-public bucket

val bucket = supabase.storage.from("avatars")
val bytes = bucket.downloadAuthenticated("test.png")
//or on JVM:
bucket.downloadAuthenticatedTo("test.png", File("test.png"))

Download file from public bucket

val bucket = supabase.storage.from("avatars")
val bytes = bucket.downloadPublic("test.png")
//or on JVM:
bucket.downloadPublicTo("test.png", File("test.png"))

Download file with transformation

val bucket = supabase.storage.from("avatars")
val bytes = bucket.downloadPublic("test.png") \{
    size(100, 100)
    fill()
    quality = 100
\}
//or on JVM:
bucket.downloadPublicTo("test.png", File("test.png")) \{
    size(100, 100)
    fill()
    quality = 100
\}

Download file with progress

val bucket = supabase.storage.from("avatars")
bucket.downloadAuthenticatedAsFlow("icon.png").collect \{
    when(it) \{
        is DownloadStatus.ByteData -> println("Downloaded $\{it.data.size\} bytes")
        is DownloadStatus.Progress -> println("Downloaded $\{it.totalBytesReceived.toFloat() / it.contentLength * 100\}%")
        DownloadStatus.Success -> println("Downloaded successfully")
    \}
\}
//or on JVM:
bucket.downloadAuthenticatedToAsFlow("icon.png", File("icon.png")).collect \{
    when(it) \{
        is DownloadStatus.Progress -> println("Downloaded $\{it.totalBytesReceived.toFloat() / it.contentLength * 100\}%")
        DownloadStatus.Success -> println("Downloaded successfully")
        else -> \{\} //The ByteData status will never occur as we are writing directly to a file
    \}
\}