HomeDocs
Skip to main content

dlt.downloadFile

Introduction

Download file resources to the local system. The client initiates an HTTPS GET request directly, which returns the file's local temporary path (local path).

Parameters

Object object

PropertyTypeDefaultRequiredDescriptionMinimum Version
urlstringYesThe address to request.
saveNamestringNoIt can be empty. If it is empty, the string after the last delimiter in the URL is taken.
headerstringNoSet the request header as a JSON string.
timeoutnumber60000NoTimeout in milliseconds. The default value is 60000.Supported since version 3.0.0
successfunctionNoA callback function that will be called when the interface is successfully invoked.
failfunctionNoA callback function that will be called when the interface is unsuccessfully invoked.
completefunctionNoA callback function that will be called when the interface call ends (whether it is successful or not).

Callback Function object.success

Parameters

Object res

AttributeTypeDescription
tempFilePathstringThe temporary download path.
successstringtrue - successful setting.

Callback Function object.fail

Parameters

Object res

AttributeTypeDescription
errCodestringError code.
errMsgstringError message.
successstringfalse - setting failed.

Explanation of errMsg

Error MessageExplanation
Download Fail, Data storage failed because of insufficient storage space: S001Download failed, insufficient storage space.
Download Fail, Exception_" + t.toString() +: D002Download failed: Exception occurred.
Download Fail, appId is empty: D003Download failed: App ID does not exist.
Download Fail, downloadUrl is error: D004Download failed: Invalid download address.
Download Fail, downloadPath is empty: D005Download failed: Download storage path is empty.
Download Fail, onFailure_" + e.toString() +: D006Download failed.
Download Fail, onResponse_" + e.toString() +: D007Download failed.

Sample Code

// pages/index/index.js

Page({
downloadFile() {
dlt.downloadFile({
url: "xxx",
success(res) {
console.log(res);
},
fail(res) {
console.error(res);
},
});
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.