跳转到内容

上传

GitHubnpmcrates.io
API Reference

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

This plugin requires a Rust version of at least 1.77.2

PlatformLevelNotes
windows
linux
macos
android
ios

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

npm run tauri add 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' } // 与请求一起发送的可选头信息
);

默认情况下,所有可能带来安全风险的插件命令(Commands)和作用域(Scopes)均处于禁止状态,无法被访问。如需启用这些功能,你必须在 capabilities 配置中显式授予相应权限。

更多信息请参阅 Capabilities 概览,以及关于如何使用插件权限的分步指南

src-tauri/capabilities/default.json
{
"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-upload
  • allow-download

Permission Table

Identifier Description

upload:allow-download

Enables the download command without any pre-configured scope.

upload:deny-download

Denies the download command without any pre-configured scope.

upload:allow-upload

Enables the upload command without any pre-configured scope.

upload:deny-upload

Denies the upload command without any pre-configured scope.


© 2026 Tauri Contributors. CC-BY / MIT