跳到内容
Tauri

上传

通过 HTTP 将文件从磁盘上传到远程服务器。将文件从远程 HTTP 服务器下载到磁盘。

此插件需要 Rust 版本至少为 **1.77.2**

平台 级别 备注
windows
linux
macos
android
ios

使用你的项目包管理器添加依赖项

npm run tauri add upload

一旦完成了插件的注册和设置过程,你就可以通过 JavaScript 客端绑定访问其所有 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

拒绝上传命令,且不带任何预配置的作用域。


© 2026 Tauri 贡献者。CC-BY / MIT