19 个版本
2.0.0-rc.0 | 2024 年 8 月 2 日 |
---|---|
2.0.0-beta.10 | 2024 年 7 月 31 日 |
2.0.0-beta.7 | 2024 年 5 月 30 日 |
2.0.0-beta.3 | 2024 年 3 月 21 日 |
2.0.0-alpha.0 | 2023 年 5 月 24 日 |
125 在 HTTP 服务器 中
每月 605 次下载
57KB
169 行
通过 HTTP 将磁盘上的文件上传到远程服务器。从远程 HTTP 服务器下载文件到磁盘。
安装
此插件需要至少 1.75 版本的 Rust
我们可以推荐三种通用的安装方法。
- 使用 crates.io 和 npm(最简单,需要您信任我们的发布流程)
- 直接从 Github 使用 git 标签/修订哈希提取源代码(最安全)
- 使用 Git 子模块在您的 tauri 项目中安装此仓库,然后使用文件协议导入源代码(最安全,但使用不便)
通过在您的 Cargo.toml
文件中添加以下内容来安装 Core 插件
src-tauri/Cargo.toml
[dependencies]
tauri-plugin-upload = "2.0.0-rc"
# alternatively with Git:
tauri-plugin-upload = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
您可以使用您喜欢的 JavaScript 包管理器安装 JavaScript Guest 绑定
注意:由于大多数 JavaScript 包管理器无法从 git monorepos 安装包,我们为每个插件提供了只读镜像。这使得安装选项 2 更易于使用。
pnpm add @tauri-apps/plugin-upload
# or
npm add @tauri-apps/plugin-upload
# or
yarn add @tauri-apps/plugin-upload
# alternatively with Git:
pnpm add https://github.com/tauri-apps/tauri-plugin-upload#v2
# or
npm add https://github.com/tauri-apps/tauri-plugin-upload#v2
# or
yarn add https://github.com/tauri-apps/tauri-plugin-upload#v2
使用方法
首先,您需要使用 Tauri 注册核心插件
src-tauri/src/main.rs
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_upload::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
之后,所有插件 API 都可以通过 JavaScript 客户端绑定访问
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`), // 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";
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
);
贡献
接受 PR。请在提交拉取请求之前确保阅读贡献指南。
合作伙伴
|
请访问我们的网站 https://tauri.org.cn#sponsors 和 Open Collective 查看赞助商的完整列表。
许可证
代码:版权所有 2015 - 现在 - Commons Conservancy 旗下的 Tauri 项目。
适用于适用的 MIT 或 MIT/Apache 2.0。
依赖项
~21–64MB
~1M SLoC