my.downloadFile

Download a file resource to a local location.

Supported types of mini programs: DSL, H5+

Sample code

copy
my.downloadFile({
  url: 'https://alidata-pub.oss-cn-hangzhou.aliyuncs.com/test.pdf',
  success(res) {
    console.log('downloadFile Success:', JSON.stringify(res, null, 2))
  },
  fail(res) {
    console.log('downloadFile Failed:', JSON.stringify(err, null, 2))
  },
});

Parameters

Property

Type

Required

Description

url

String

Yes

Downloading file address.

filePath

String

No

After the file is downloaded, you can rename the file when calling the my.openDocument JSAPI to preview and share the PDF.

Note: The length is limited to 70 characters.

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).

Success Callback Function

The incoming parameter is of the Object type with the following attributes:

PropertyTypeDescription
apFilePathStringTemporary file storage location.

Error Code

Error code

Error message

Further action

2

invalid parameter!

Refer to the previous Parameters table to ensure that all parameters are specified correctly, and that all required parameters are provided.

12

Failed to download.

Failed to download the file. Please check your network connection and server status.

13

Failed to move file.

Failed to move file. Please check storage permissions.