コンテンツにスキップ
Tauri

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 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」の章を参照してください。また、プラグインのアクセス権限を設定するには「プライグン・アクセス権の使用」の章のステップ・バイ・ステップ・ガイドを参照してください。

src-tauri/capabilities/default.json
{
"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-upload
  • allow-download

Permission Table

Identifier Description

upload:allow-download

Enables the download command without any pre-configured scope.

upload:deny-download

Denies the download command without any pre-configured scope.

upload:allow-upload

Enables the upload command without any pre-configured scope.

upload:deny-upload

Denies the upload command without any pre-configured scope.

【※ この日本語版は、「Feb 22, 2025 英語版」に基づいています】


© 2025 Tauri Contributors. CC-BY / MIT