- Add InsForge dependencies to your project
Maven Central
GitHub Packages
First, create a GitHub Personal Access Token:
- Go to GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic)
- Select permission:
read:packages
Then configure your project using one of the following methods:Option A: Environment Variables
settings.gradle.kts (or build.gradle.kts):build.gradle.kts:Set environment variables before building: Option B: gradle.properties (Local Development)
Add credentials to your global Gradle properties file:~/.gradle/gradle.properties:settings.gradle.kts:build.gradle.kts:The ~/.gradle/gradle.properties file is stored outside your project, so credentials won’t be accidentally committed to version control.
- Initialize InsForge SDK
- Enable Logging (Optional)
For debugging, you can configure the SDK log level:
| Log Level | Description |
|---|
NONE | No logging (default, recommended for production) |
ERROR | Only errors |
WARN | Warnings and errors |
INFO | Informational messages |
DEBUG | Debug info (request method, URL, response status) |
VERBOSE | Full details (headers, request/response bodies) |
Use NONE or ERROR in production to avoid exposing sensitive data in logs.
Android Initialization
- Add Chrome Custom Tabs dependency to your
build.gradle.kts:
- Initialize InsForge SDK (With Chrome Custom Tabs and Session Storage)
- Use Jetpack DataStore for Session Storage (Optional)
from()
取得用於檔案作業的貯體執行個體。
upload()
上傳具有特定路徑/金鑰的檔案。
path (String) - 貯體中的檔案路徑/金鑰
data (ByteArray) - 檔案內容(以位元組形式)
options (DSL block, optional) - 上傳選項
UploadOptions
| 選項 | 類型 | 說明 |
|---|
contentType | String? | MIME 類型(例如 “image/jpeg”) |
upsert | Boolean | 如果檔案存在,覆寫(預設:false) |
metadata | Map\<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 選項
| 選項 | 類型 | 說明 |
|---|
prefix | String? | 按路徑首碼篩選 |
limit | Int | 最大結果數(預設:100) |
offset | Int | 分頁位移(預設:0) |
sortBy | String? | 排序欄位 |
sortOrder | SortOrder | ASC 或 DESC(預設:ASC) |
貯體管理
listBuckets()
列出所有儲存空間貯體。
createBucket()
建立新儲存空間貯體。
updateBucket()
更新貯體設定。
deleteBucket()
刪除儲存空間貯體。
進階上傳
getUploadStrategy()
取得用於大型檔案或可繼續上傳的上傳策略。
confirmUpload()
確認已完成的上傳。