Android Example [B4X] Supabase - Storage Bucket


This is a very simple tutorial on how to use the storage bucket options.

CREATE
Creates a new Storage bucket
Name - A unique identifier for the bucket you are creating
B4X:
    Dim CreateBucket As Supabase_StorageBucket = xSupabase.Storage.CreateBucket("Avatar")
    CreateBucket.Options_isPublic(False)
    CreateBucket.Options_FileSizeLimit(1048576 )
    CreateBucket.Options_AllowedMimeTypes(Array("image/png","image/jpg"))
    Wait For (CreateBucket.Execute) Complete (Bucket As SupabaseStorageBucket)
    If Bucket.Error.Success Then
        Log($"Bucket ${Bucket.Name} successfully created "$)
    Else
        Log("Error: " & Bucket.Error.ErrorMessage)
    End If
READ
Retrieves the details of an existing Storage bucket.
B4X:
    Dim GetBucket As Supabase_StorageBucket = xSupabase.Storage.GetBucket("Avatar")
    Wait For (GetBucket.Execute) Complete (Bucket As SupabaseStorageBucket)
    If Bucket.Error.Success Then
        Log($"Bucket ${Bucket.Name} was created at ${DateUtils.TicksToString(Bucket.CreatedAt)}"$)
    Else
        Log("Error: " & Bucket.Error.ErrorMessage)
    End If
UPDATE
Updates a new Storage bucket
B4X:
    Dim UpdateBucket As Supabase_StorageBucket = xSupabase.Storage.UpdateBucket("Avatar")
    UpdateBucket.Options_isPublic(True)
    UpdateBucket.Options_FileSizeLimit(1048576 )
    UpdateBucket.Options_AllowedMimeTypes(Array("image/png"))
    Wait For (UpdateBucket.Execute) Complete (Bucket As SupabaseStorageBucket)
    If Bucket.Error.Success Then
        Log($"Bucket ${Bucket.Name} successfully updated "$)
    Else
        Log("Error: " & Bucket.Error.ErrorMessage)
    End If
DELETE
Deletes an existing bucket. A bucket can't be deleted with existing objects inside it. You must first empty() the bucket.
B4X:
    Dim DelteBucket As Supabase_StorageBucket = xSupabase.Storage.DeleteBucket("Avatar")
    Wait For (DelteBucket.Execute) Complete (Bucket As SupabaseStorageBucket)
    If Bucket.Error.Success Then
        Log($"Bucket ${Bucket.Name} successfully deleted "$)
    Else
        Log("Error: " & Bucket.Error.ErrorMessage)
    End If
Empty Bucket
Removes all objects inside a single bucket.
B4X:
    Wait For (xSupabase.Storage.EmptyBucket("Avatar").Execute) Complete (Bucket As SupabaseStorageBucket)
    If Bucket.Error.Success Then
        Log($"Bucket ${Bucket.Name} successfully cleared "$)
    Else
        Log("Error: " & Bucket.Error.ErrorMessage)
    End If
 
Top