* feat(http, upload): update reqwest to 0.13 `tauri-plugin-http` re-exports `reqwest`, so moving it is a breaking change and belongs on v3 rather than v2 (#3462). `tauri-plugin-updater` already took 0.13 in #3213; these two follow the same shape. `rustls-tls` maps to `reqwest/rustls-no-provider` plus `rustls` with `ring`, and the provider is installed as the process default only when none is set yet, exactly as the updater does. Without it `reqwest::Client::new()` has no crypto provider to build with. Features reqwest 0.13 removed are removed here rather than remapped silently: - `native-tls-alpn`: ALPN is part of `native-tls` now. - `rustls-tls-manual-roots`, `rustls-tls-webpki-roots`, `rustls-tls-native-roots`: certificate verification goes through the platform verifier. - `trust-dns`: renamed `hickory-dns`. - `macos-system-configuration`: superseded by `system-proxy`, which the default feature set already carries and which the deprecation note pointed at. Verified with the CI commands for both packages: clippy --all-targets and clippy --all-targets --all-features under -D warnings, cargo test (http 8, upload 7 with --all-features), and cargo fmt --all --check. * feat(http): drop the reqwest re-export * chore(http): drop duplicate macos-system-configuration changelog entry * remove .tauri --------- Co-authored-by: Lucas Nogueira <lucas@tauri.app>
Upload files from disk to a remote server over HTTP. Download files from a remote HTTP server to disk.
| Platform | Supported |
|---|---|
| Linux | ✓ |
| Windows | ✓ |
| macOS | ✓ |
| Android | ✓ |
| iOS | ✓ |
Install
This plugin requires a Rust version of at least 1.95
There are three general methods of installation that we can recommend.
- Use crates.io and npm (easiest, and requires you to trust that our publishing pipeline worked)
- Pull sources directly from Github using git tags / revision hashes (most secure)
- Git submodule install this repo in your tauri project and then use file protocol to ingest the source (most secure, but inconvenient to use)
Install the Core plugin by adding the following to your Cargo.toml file:
src-tauri/Cargo.toml
[dependencies]
tauri-plugin-upload = "2.0.0"
# alternatively with Git:
tauri-plugin-upload = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
You can install the JavaScript Guest bindings using your preferred JavaScript package manager:
pnpm add @tauri-apps/plugin-upload
# or
npm add @tauri-apps/plugin-upload
# or
yarn add @tauri-apps/plugin-upload
Usage
First you need to register the core plugin with Tauri:
src-tauri/src/lib.rs
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_upload::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
import { upload, HttpMethod } from '@tauri-apps/plugin-upload'
// Upload with default POST method
upload(
'https://example.com/file-upload',
'./path/to/my/file.txt',
({ progressTotal, total }) =>
console.log(`Uploaded ${progressTotal} of ${total} bytes`), // a callback that will be called with the upload progress
{ headers: { 'Content-Type': 'text/plain' } } // optional headers to send with the request
)
// Upload with specific HTTP method
upload(
'https://example.com/file-upload',
'./path/to/my/file.txt',
({ progressTotal, total }) =>
console.log(`Uploaded ${progressTotal} of ${total} bytes`),
{
headers: { 'Content-Type': 'text/plain' },
method: HttpMethod.Put // Use HttpMethod enum - supports POST, PUT, PATCH
}
)
import { download } from '@tauri-apps/plugin-upload'
download(
'https://example.com/file-download-link',
'./path/to/save/my/file.txt',
({ progressTotal, total }) =>
console.log(`Downloaded ${progressTotal} of ${total} bytes`), // a callback that will be called with the download progress
{ headers: { 'Content-Type': 'text/plain' } } // optional headers to send with the request
)
Contributing
PRs accepted. Please make sure to read the Contributing Guide before making a pull request.
Partners
|
|
For the complete list of sponsors please visit our website and Open Collective.
License
Code: (c) 2015 - Present - The Tauri Programme within The Commons Conservancy.
MIT or MIT/Apache 2.0 where applicable.
