mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-22 21:30:44 +02:00
refactor(upload)!: take headers, method and body via an options object (#3613)
`upload(url, path, onProgress, { headers, method })` and
`download(url, path, onProgress, { headers, body })` replace the
positional optional arguments.
`headers` accepts both a `Map` and a plain object; previously a `Map`
was silently serialized as an empty object.
This commit is contained in:
@@ -68,7 +68,7 @@ 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
|
||||
{ 'Content-Type': 'text/plain' } // optional headers to send with the request
|
||||
{ headers: { 'Content-Type': 'text/plain' } } // optional headers to send with the request
|
||||
)
|
||||
|
||||
// Upload with specific HTTP method
|
||||
@@ -77,8 +77,10 @@ upload(
|
||||
'./path/to/my/file.txt',
|
||||
({ progressTotal, total }) =>
|
||||
console.log(`Uploaded ${progressTotal} of ${total} bytes`),
|
||||
{ 'Content-Type': 'text/plain' },
|
||||
HttpMethod.Put // Use HttpMethod enum - supports POST, PUT, PATCH
|
||||
{
|
||||
headers: { 'Content-Type': 'text/plain' },
|
||||
method: HttpMethod.Put // Use HttpMethod enum - supports POST, PUT, PATCH
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
@@ -90,7 +92,7 @@ download(
|
||||
'./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
|
||||
{ 'Content-Type': 'text/plain' } // optional headers to send with the request
|
||||
{ headers: { 'Content-Type': 'text/plain' } } // optional headers to send with the request
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user