ionic-team / ionic-team/capacitor-file-transfer
FileTransfer.downloadFile should support request bodies
- Dominant language
- TypeScript
- Stars
- 11
- Forks
- 10
- PR merge metrics
- No merged PRs in 30d
Description
## Feature Request
### Plugin
The `FileTransfer` plugin
### Description
The `downloadFile` utility is typed to take, as a prop, the `DownloadFileOptions`, which extends `HttpOptions`. This includes the ability to set the `data`.
I intend to use the File Transfer plugin to download files from an API that requires me to `POST` an ID to a URL. Initially, when looking at just the TypeScript types I was led to assume this is possible, but it is not, as the actual implementations of the plugin (on both Android and iOS) ignore the `data` set in the props.
My specific usecase also requires the request body to be an `ArrayBuffer` due to usage of Protobufs.
### Platform(s)
Android, iOS
### Preferred Solution
The plugin should behave as described by its TypeScript typings, where `DownloadFileOptions` extends `HttpOptions` and as such lets me pass `data`, `headers` and `dataType`.
### Alternatives
I have considered not using the File Transfer plugin and instead rolling my own file downloader that supports my specific usecase, but I would prefer if this plugin was adjusted to be able to send a request body.
### Additional Context
Expected code to work:
```ts
const fileInfo = await Filesystem.getUri({
directory: Directory.Documents,
path: "download" // TODO: Better name
})
const body = toBinary(DocumentDownloadRequestSchema, request);
const result = await FileTransfer.downloadFile({
url: host + "room/document/download?token=" + encodeURIComponent(token),
path: fileInfo.uri,
method: "POST",
data: toBase64(body),
dataType: "file",
headers: {
"Content-Type": "application/x-protobuf",
"accept": "application/octet-stream"
}
})
```
Which fails with a 404 due to the backend not receiving the protobuf.
Contributor guide
Assessment
This issue has not been assessed yet.