Upload(アップロード)
Plugin 説明内容の英語表記部分について Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。
HTTP 経由でディスクからリモートサーバーにファイルをアップロードします。リモート HTTP サーバーからディスクにファイルをダウンロードします。
This plugin requires a Rust version of at least 1.77.2
| Platform | Level | Notes |
|---|---|---|
| windows | ||
| linux | ||
| macos | ||
| android | ||
| ios |
自分のプロジェクトのパッケージ・マネージャーを使用して依存関係を追加します:
npm run tauri add uploadyarn run tauri add uploadpnpm tauri add uploaddeno task tauri add uploadbun tauri add uploadcargo tauri add upload-
src-tauriフォルダで次のコマンドを実行して、このプラグインをCargo.toml内のプロジェクトの依存関係に追加します:cargo add tauri-plugin-upload -
追加したプラグインを初期化するために
lib.rsを修正します:src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().plugin(tauri_plugin_upload::init()).run(tauri::generate_context!()).expect("error while running tauri application");} -
お好みの JavaScript パッケージ・マネージャーを使用して、「JavaScript Guest」バインディングをインストールします:
npm install @tauri-apps/plugin-uploadyarn add @tauri-apps/plugin-uploadpnpm add @tauri-apps/plugin-uploaddeno add npm:@tauri-apps/plugin-uploadbun add @tauri-apps/plugin-upload
このプラグインの登録とセットアップのプロセスが完了すると、「JavaScript Guest」バインディングを通じてすべての API にアクセスできるようになります。
以下に、このプラグインを使用してファイルのアップロードおよびダウンロードを行なう事例を示します:
import { upload } from '@tauri-apps/plugin-upload';// `"withGlobalTauri": true` を使用する場合は、// const { upload } = window.__TAURI__.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';// `"withGlobalTauri": true` を使用する場合は、// const { download } = window.__TAURI__.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' } // コールバック要求とともに送信するオプションのヘッダー);デフォルトでは、潜在的に危険なプラグイン・コマンドとそのスコープ(有効範囲)はすべてブロックされており、アクセスできません。これらを有効にするには、capabilities 設定でアクセス権限を変更する必要があります。
詳細については「セキュリティ・レベル Capabilities」の章を参照してください。また、プラグインのアクセス権限を設定するには「プライグン・アクセス権の使用」の章のステップ・バイ・ステップ・ガイドを参照してください。
{ "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-uploadallow-download
Permission Table
| Identifier | Description |
|---|---|
|
|
Enables the download command without any pre-configured scope. |
|
|
Denies the download command without any pre-configured scope. |
|
|
Enables the upload command without any pre-configured scope. |
|
|
Denies the upload command without any pre-configured scope. |
【※ この日本語版は、「Feb 22, 2025 英語版」に基づいています】
© 2025 Tauri Contributors. CC-BY / MIT