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:
Lucas Fernandes Nogueira
2026-09-22 06:07:43 -03:00
committed by GitHub
parent b2d7c387ef
commit 0ecb30e3cb
5 changed files with 94 additions and 25 deletions
+6 -4
View File
@@ -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
)
```