跳轉到主要內容

安裝

  1. Add InsForge dependencies to your project
build.gradle.kts:
  1. Initialize InsForge SDK
  1. Enable Logging (Optional)
For debugging, you can configure the SDK log level:
Log LevelDescription
NONENo logging (default, recommended for production)
ERROROnly errors
WARNWarnings and errors
INFOInformational messages
DEBUGDebug info (request method, URL, response status)
VERBOSEFull details (headers, request/response bodies)
Use NONE or ERROR in production to avoid exposing sensitive data in logs.

Android Initialization

  1. Add Chrome Custom Tabs dependency to your build.gradle.kts:
  1. Initialize InsForge SDK (With Chrome Custom Tabs and Session Storage)
  1. Use Jetpack DataStore for Session Storage (Optional)

from()

取得用於檔案作業的貯體執行個體。

範例


upload()

上傳具有特定路徑/金鑰的檔案。

參數

  • path (String) - 貯體中的檔案路徑/金鑰
  • data (ByteArray) - 檔案內容(以位元組形式)
  • options (DSL block, optional) - 上傳選項

UploadOptions

選項類型說明
contentTypeString?MIME 類型(例如 “image/jpeg”)
upsertBoolean如果檔案存在,覆寫(預設:false)
metadataMap\<String, String\>?自訂中繼資料

範例

從 Android Uri 上傳

開發者可以使用下列函式從 Android Uri 上傳檔案:

uploadWithAutoKey()

上傳具有自動產生的唯一金鑰的檔案。

參數

  • filename (String) - 原始檔案名稱(用於副檔名偵測)
  • data (ByteArray) - 檔案內容(以位元組形式)
  • options (DSL block, optional) - 上傳選項

範例


download()

將檔案下載為 ByteArray。

範例


delete()

從儲存空間中刪除檔案。

範例


createSignedUrl()

為檔案暫時存取建立簽署的 URL。

參數

  • path (String) - 貯體中的檔案路徑
  • expiresIn (Int) - 過期時間(以秒為單位)

範例


getDownloadUrl()

取得檔案的下載 URL。

範例


list()

列出貯體中具有選擇性篩選的檔案。

BucketListFilter 選項

選項類型說明
prefixString?按路徑首碼篩選
limitInt最大結果數(預設:100)
offsetInt分頁位移(預設:0)
sortByString?排序欄位
sortOrderSortOrderASC 或 DESC(預設:ASC)

範例


貯體管理

listBuckets()

列出所有儲存空間貯體。

createBucket()

建立新儲存空間貯體。

updateBucket()

更新貯體設定。

deleteBucket()

刪除儲存空間貯體。

進階上傳

getUploadStrategy()

取得用於大型檔案或可繼續上傳的上傳策略。

confirmUpload()

確認已完成的上傳。