上传
通过 HTTP 从磁盘上传文件到远程服务器。从远程 HTTP 服务器下载文件到磁盘。
This plugin requires a Rust version of at least 1.77.2
| Platform | Level | Notes |
|---|---|---|
| windows | ||
| linux | ||
| macos | ||
| android | ||
| ios |
使用项目的包管理器来添加依赖。
npm run tauri add uploadyarn run tauri add uploadpnpm tauri add uploaddeno task tauri add uploadbun tauri add uploadcargo tauri add upload-
在
src-tauri文件夹中运行以下命令,将插件添加到Cargo.toml中的项目依赖项中。cargo add tauri-plugin-upload -
修改
lib.rs来初始化插件。src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().plugin(tauri_plugin_upload::init()).run(tauri::generate_context!()).expect("error while running tauri application");} -
使用你喜欢的 JavaScript 包管理器安装 JavaScript Guest 绑定。
npm install @tauri-apps/plugin-uploadyarn add @tauri-apps/plugin-uploadpnpm add @tauri-apps/plugin-uploaddeno add npm:@tauri-apps/plugin-uploadbun add @tauri-apps/plugin-upload
一旦完成了插件的注册和设置过程,就可以通过 JavaScript Guest 绑定访问它的所有 API。
下面是一个使用插件上传和下载文件的例子:
import { upload } from '@tauri-apps/plugin-upload';
upload( 'https://example.com/file-upload', './path/to/my/file.txt', ({ progress, total }) => console.log(`Uploaded ${progress} of ${total} bytes`), // 上传进度时调用的回调函数 { 'Content-Type': 'text/plain' } // 与请求一起发送的可选头信息);import { download } from '@tauri-apps/plugin-upload';
download( 'https://example.com/file-download-link', './path/to/save/my/file.txt', ({ progress, total }) => console.log(`Downloaded ${progress} of ${total} bytes`), // 下载进度时调用的回调函数 { 'Content-Type': 'text/plain' } // 与请求一起发送的可选头信息);权限(Permissions)
Section titled “权限(Permissions)”默认情况下,所有可能带来安全风险的插件命令(Commands)和作用域(Scopes)均处于禁止状态,无法被访问。如需启用这些功能,你必须在 capabilities 配置中显式授予相应权限。
更多信息请参阅 Capabilities 概览,以及关于如何使用插件权限的分步指南。
{ "permissions": [ ..., "upload:default" ]}Default Permission
This permission set configures what kind of operations are available from the upload plugin.
Granted Permissions
All operations are enabled by default.
This default permission set includes the following:
allow-uploadallow-download
Permission Table
| Identifier | Description |
|---|---|
|
|
Enables the download command without any pre-configured scope. |
|
|
Denies the download command without any pre-configured scope. |
|
|
Enables the upload command without any pre-configured scope. |
|
|
Denies the upload command without any pre-configured scope. |
© 2026 Tauri Contributors. CC-BY / MIT