跳转到内容
Tauri

上传

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

设置

这个插件要求 Rust 版本至少是 1.75

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

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

© 2024 Tauri Contributors. CC-BY / MIT