Skip to content

Commit e16eb38

Browse files
dreyfus92vasfvitor
andauthored
docs(features): update upload.mdx (#1924)
* docs(features): update `upload.mdx` * fix: format * update: usage * Apply suggestion from vasfvitor's review. Co-authored-by: Vitor Ayres <[email protected]> --------- Co-authored-by: Vitor Ayres <[email protected]>
1 parent 7e8b0e0 commit e16eb38

File tree

1 file changed

+80
-5
lines changed

1 file changed

+80
-5
lines changed

src/content/docs/features/upload.mdx

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,87 @@ title: Upload
33
description: File uploads through HTTP.
44
---
55

6-
import Stub from '@components/Stub.astro';
76
import PluginLinks from '@components/PluginLinks.astro';
7+
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';
8+
import CommandTabs from '@components/CommandTabs.astro';
89

910
<PluginLinks plugin="upload" />
1011

11-
<Stub>
12-
Based on
13-
https://github.com/tauri-apps/plugins-workspace/tree/v2/plugins/upload
14-
</Stub>
12+
Upload files from disk to a remote server over HTTP. Download files from a remote HTTP server to disk.
13+
14+
## Setup
15+
16+
_This plugin requires a Rust version of at least **1.75**_
17+
18+
<Tabs>
19+
<TabItem label="Automatic">
20+
21+
Use your project's package manager to add the dependency:
22+
23+
<CommandTabs
24+
npm="npm run tauri add upload"
25+
yarn="yarn run tauri add upload"
26+
pnpm="pnpm tauri add upload"
27+
cargo="cargo tauri add upload"
28+
/>
29+
30+
</TabItem>
31+
<TabItem label="Manual">
32+
33+
<Steps>
34+
35+
1. Run `cargo add tauri-plugin-upload` to add the plugin to the project's dependencies in `Cargo.toml`.
36+
37+
2. Modify `lib.rs` to initialize the plugin:
38+
39+
```rust title="src-tauri/src/lib.rs" ins={5}
40+
#[cfg_attr(mobile, tauri::mobile_entry_point)]
41+
pb fn run() {
42+
tauri::Builder::default()
43+
// Initialize the plugin
44+
.plugin(tauri_plugin_upload::init())
45+
.run(tauri::generate_context!())
46+
.expect("error while running tauri application");
47+
}
48+
```
49+
50+
3. Install the JavaScript Guest bindings using your preferred JavaScript package manager:
51+
52+
<CommandTabs
53+
npm="npm install @tauri-apps/plugin-upload"
54+
yarn="yarn add @tauri-apps/plugin-upload"
55+
pnpm="pnpm add @tauri-apps/plugin-upload"
56+
/>
57+
58+
</Steps>
59+
</TabItem>
60+
61+
</Tabs>
62+
63+
## Usage
64+
65+
Once you've completed the registration and setup process for the plugin, you can access all of its APIs through the JavaScript guest bindings.
66+
67+
Here's an example of how you can use the plugin to upload and download files:
68+
69+
```js
70+
import { upload } from 'tauri-plugin-upload-api';
71+
72+
upload(
73+
'https://example.com/file-upload',
74+
'./path/to/my/file.txt',
75+
(progress, total) => console.log(`Uploaded ${progress} of ${total} bytes`), // a callback that will be called with the upload progress
76+
{ 'Content-Type': 'text/plain' } // optional headers to send with the request
77+
);
78+
```
79+
80+
```js
81+
import { download } from 'tauri-plugin-upload-api';
82+
83+
download(
84+
'https://example.com/file-download-link',
85+
'./path/to/save/my/file.txt',
86+
(progress, total) => console.log(`Downloaded ${progress} of ${total} bytes`), // a callback that will be called with the download progress
87+
{ 'Content-Type': 'text/plain' } // optional headers to send with the request
88+
);
89+
```

0 commit comments

Comments
 (0)