跳到內容
Tauri

上傳

透過 HTTP 從磁碟上傳檔案到遠端伺服器。從遠端 HTTP 伺服器下載檔案到磁碟。

支援平台

此插件需要至少 1.77.2 的 Rust 版本

平台 層級 註解
windows
linux
macos
android
ios

設定

使用您專案的套件管理器新增依賴項

npm run tauri add upload

使用方式

一旦您完成插件的註冊和設定流程,您就可以透過 JavaScript Guest 綁定存取其所有 API。

以下是如何使用插件上傳和下載檔案的範例

import { upload } from '@tauri-apps/plugin-upload';
// when using `"withGlobalTauri": true`, you may use
// const { upload } = window.__TAURI__.upload;
upload(
'https://example.com/file-upload',
'./path/to/my/file.txt',
({ progress, total }) =>
console.log(`Uploaded ${progress} of ${total} bytes`), // a callback that will be called with the upload progress
{ 'Content-Type': 'text/plain' } // optional headers to send with the request
);
import { download } from '@tauri-apps/plugin-upload';
// when using `"withGlobalTauri": true`, you may use
// const { download } = window.__TAURI__.upload;
download(
'https://example.com/file-download-link',
'./path/to/save/my/file.txt',
({ progress, total }) =>
console.log(`Downloaded ${progress} of ${total} bytes`), // a callback that will be called with the download progress
{ 'Content-Type': 'text/plain' } // optional headers to send with the request
);

權限

預設情況下,所有潛在危險的插件指令和範圍都被封鎖,無法存取。您必須修改 capabilities 組態中的權限才能啟用這些。

有關更多資訊,請參閱功能概述,以及使用插件權限的逐步指南

src-tauri/capabilities/default.json
{
"permissions": [
...,
"upload:default",
]
}

預設權限

此權限集設定了可從上傳插件取得的操作類型。

已授權的權限

預設情況下,所有操作都已啟用。

  • allow-upload
  • allow-download

權限表

識別符 描述

upload:allow-download

啟用下載指令,無需任何預先設定的範圍。

upload:deny-download

拒絕下載指令,無需任何預先設定的範圍。

upload:allow-upload

啟用上傳指令,無需任何預先設定的範圍。

upload:deny-upload

拒絕上傳指令,無需任何預先設定的範圍。


© 2025 Tauri 貢獻者。CC-BY / MIT