Upload
Upload files from disk to a remote server over HTTP. Download files from a remote HTTP server to disk.
This plugin requires a Rust version of at least 1.75
Use your project’s package manager to add the dependency:
npm run tauri add uploadyarn run tauri add uploadpnpm tauri add uploadcargo tauri add upload-
Run
cargo add tauri-plugin-uploadto add the plugin to the project’s dependencies inCargo.toml. -
Modify
lib.rsto initialize the plugin:src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pb fn run() {tauri::Builder::default()// Initialize the plugin.plugin(tauri_plugin_upload::init()).run(tauri::generate_context!()).expect("error while running tauri application");} -
Install the JavaScript Guest bindings using your preferred JavaScript package manager:
Terminal window npm install @tauri-apps/plugin-uploadTerminal window yarn add @tauri-apps/plugin-uploadTerminal window pnpm add @tauri-apps/plugin-upload
Once you’ve completed the registration and setup process for the plugin, you can access all of its APIs through the JavaScript guest bindings.
Here’s an example of how you can use the plugin to upload and download files:
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);© 2024 Tauri Contributors. CC-BY / MIT