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

ErrorDescription
12Downloading failed.
13No right.