my.downloadFile downloads a file from a remote server to a local location. The downloaded file path is returned in the success callback and can be used with other APIs like my.previewImage or my.openDocument.
my.downloadFile({
url: 'http://img.example.com/example.jpg',
success: ({ apFilePath }) => {
my.previewImage({
urls: [apFilePath],
});
},
fail: (res) => {
my.alert({
content: res.errorMessage || res.error,
});
},
});
| Property | Type | Required | Description |
|---|---|---|---|
url | String | Yes | Downloading file address. |
header | Object | No | HTTP request Header. |
success | Function | No | Callback function upon call success. |
fail | Function | No | Callback function upon call failure. |
complete | Function | No | Callback function upon call completion (to be executed upon either call success or failure). |
The incoming parameter is of the Object type with the following attributes:
| Property | Type | Description |
|---|---|---|
apFilePath | String | Temporary file storage location. |
| Error | Description |
|---|---|
12 | Downloading failed. |
13 | No right. |
apFilePath with APIs like my.previewImage, my.openDocument, or my.saveFileheader parametermy.saveFile to persist it