跳至正文內容
TursoDB.cn 獨立社群 · MVCC 並行寫入與每 Agent 獨立庫實戰 閱讀解析 →
Turso Cloud API 參考 介面資源 資料庫

上傳資料庫

上傳資料庫 — Turso 文件。

將 SQLite 資料庫檔案上傳至以 seed.type = "database_upload" 建立的資料庫。

注意

此端點位於資料庫主機名稱(例如 my-db-my-org.turso.io),而非 api.turso.tech。

注意

您必須先以 seed.type = "database_upload" 建立資料庫。

注意

此端點需要資料庫權杖,而非平台 API 權杖。您可以在建立資料庫後建立資料庫權杖。

標頭

標頭 必填 說明
Authorization 是 資料庫的 Bearer 權杖
Content-Length 是 資料庫檔案大小(位元組)
x-turso-encryption-key 否 Base64 編碼的加密金鑰(256 位元加密為 32 位元組,128 位元加密為 16 位元組)
x-turso-encryption-cipher 否 加密演算法。選項請見下表。

請求本文

原始二進位 SQLite 資料庫檔案。

資料庫檔案需求

SQLite 資料庫檔案必須符合以下需求:

  • 日誌模式:WAL (PRAGMA journal_mode = WAL)
  • 頁面大小:4096 位元組 (PRAGMA page_size = 4096)
  • 自動清理:停用 (PRAGMA auto_vacuum = 0)
  • 編碼:UTF-8 (PRAGMA encoding = 'UTF-8')

若為加密資料庫,您還必須設定保留位元組以符合加密演算法:

加密演算法 保留位元組
aes256gcm 28
aes128gcm 28
chacha20poly1305 28
aegis128l 32
aegis128x2 32
aegis128x4 32
aegis256 48
aegis256x2 48
aegis256x4 48

回應

成功

成功時傳回狀態為 200 OK 的空回應。

錯誤

狀態 說明
400 資料庫檔案無效(格式錯誤、設定不正確或檔案損毀)
401 授權權杖無效或缺少
curl -X POST 'https://{database_hostname}/v1/upload' \
  -H 'Authorization: Bearer DATABASE_TOKEN' \
  -H 'Content-Length: FILE_SIZE' \
  --data-binary '@/path/to/database.db'
curl -X POST 'https://{database_hostname}/v1/upload' \
  -H 'Authorization: Bearer DATABASE_TOKEN' \
  -H 'Content-Length: FILE_SIZE' \
  -H 'x-turso-encryption-key: BASE64_ENCRYPTION_KEY' \
  -H 'x-turso-encryption-cipher: aes256gcm' \
  --data-binary '@/path/to/database.db'
同步自官方 Turso 文件倉庫 ( tursodatabase/turso-docs · MIT 開源授權) 檢視官方原文 ↗
搜尋
按 Esc 關閉 · 由 Pagefind 靜態索引驅動