benxu.AppPlatform.Supabase.Storage 3.2.8

dotnet add package benxu.AppPlatform.Supabase.Storage --version 3.2.8
                    
NuGet\Install-Package benxu.AppPlatform.Supabase.Storage -Version 3.2.8
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="benxu.AppPlatform.Supabase.Storage" Version="3.2.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="benxu.AppPlatform.Supabase.Storage" Version="3.2.8" />
                    
Directory.Packages.props
<PackageReference Include="benxu.AppPlatform.Supabase.Storage" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add benxu.AppPlatform.Supabase.Storage --version 3.2.8
                    
#r "nuget: benxu.AppPlatform.Supabase.Storage, 3.2.8"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package benxu.AppPlatform.Supabase.Storage@3.2.8
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=benxu.AppPlatform.Supabase.Storage&version=3.2.8
                    
Install as a Cake Addin
#tool nuget:?package=benxu.AppPlatform.Supabase.Storage&version=3.2.8
                    
Install as a Cake Tool

benxu.AppPlatform.Supabase.Storage

Supabase Storage 實作套件,提供物件檔案的上傳、更新、下載、列舉、刪除、搬移、複製,以及公開網址與簽名網址產生能力,適合在 .NET MAUI App 中存取 Supabase Storage。

功能特色

  • 使用 Supabase.Storage 實作常用的物件儲存操作。
  • 提供 Upload / Update / Download / List / Delete / Move / Copy 服務介面。
  • 支援 GetPublicUrlCreateSignedUrlCreateSignedUrls
  • 若系統中已有 IAuthService,可自動帶入使用者 JWT,配合 Supabase Storage 權限規則。
  • 保持套件內聚,不將遠端儲存抽象提升到既有平台 Core 層。

安裝

dotnet add package benxu.AppPlatform.Supabase.Storage

使用方式

1. 直接註冊服務

using benxu.AppPlatform.Supabase.Storage.Extensions;

builder.Services.AddSupabaseStorage(options =>
{
    options.ProjectUrl = "https://your-project.supabase.co";
    options.AnonKey = "YOUR_SUPABASE_ANON_KEY";
    options.UseAuthTokenWhenAvailable = true;
});

2. 透過 Bootstrap 註冊

using benxu.AppPlatform.MAUI.Bootstrap.Extensions;

builder.UseAppPlatform(options =>
{
    options.UseSupabaseStorage(storage =>
    {
        storage.ProjectUrl = "https://your-project.supabase.co";
        storage.AnonKey = "YOUR_SUPABASE_ANON_KEY";
        storage.UseAuthTokenWhenAvailable = true;
    });
});

3. 上傳與下載檔案

using benxu.AppPlatform.Supabase.Storage.Abstractions;

public class AvatarStorageService
{
    private readonly ISupabaseStorageService _storageService;

    /// <summary>
    /// 建立 AvatarStorageService。
    /// </summary>
    /// <param name="storageService">Supabase Storage 服務。</param>
    public AvatarStorageService(ISupabaseStorageService storageService)
    {
        _storageService = storageService;
    }

    /// <summary>
    /// 上傳使用者頭像並回傳可用網址。
    /// </summary>
    /// <param name="userId">使用者識別碼。</param>
    /// <param name="localFilePath">本機檔案路徑。</param>
    /// <returns>頭像公開網址;若失敗則回傳 <see langword="null"/>。</returns>
    public async Task<string?> UploadAvatarAsync(string userId, string localFilePath)
    {
        var objectPath = $"avatars/{userId}.jpg";

        var uploadResult = await _storageService.UploadAsync(
            "user-assets",
            localFilePath,
            objectPath);

        if (uploadResult.IsFailure)
        {
            return null;
        }

        var publicUrlResult = await _storageService.GetPublicUrlAsync(
            "user-assets",
            objectPath);

        return publicUrlResult.IsSuccess ? publicUrlResult.Data : null;
    }
}

注意事項

  • bucketNameobjectPath 不可為空。
  • 本機檔案上傳前會驗證檔案是否存在。
  • RequireAuthenticatedSession = true,但目前沒有可用的 Access Token,服務會直接回傳失敗結果。
  • GetPublicUrlAsync() 僅負責產生 URL,不會檢查 bucket 是否真的是 public。

依賴項目

  • Supabase.Storage (2.4.1)
  • benxu.AppPlatform.Core
  • Microsoft.Maui.Controls

授權

MIT License

Product Compatible and additional computed target framework versions.
.NET net10.0-android36.0 is compatible.  net10.0-ios26.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on benxu.AppPlatform.Supabase.Storage:

Package Downloads
benxu.AppPlatform.MAUI.Bootstrap

Bootstrap package for benxu App Platform. Provides fluent API for one-line service registration and lifecycle management.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.2.8 53 7/7/2026