HomeDocs
Skip to main content

dlt.uploadFile

Introduction

Uploads local resources to a server. The client initiates an HTTPS POST request with the content-type set to multipart/form-data.

Parameters

Object object

AttributeTypeDefaultRequiredDescriptionMinimum Version
urlstringYesThe request URL.
headerstringNoThe request header in JSON string format.
formDatastring/ObjectNoOther additional form data in the HTTP request. If it's an Object, make sure the values are of string type.
filePathstringNoThe path where the downloaded file will be stored (relative path).3.0.0
timeoutnumber60000NoTimeout duration in milliseconds. The default value is 60000 (60 seconds).3.0.0
successfunctionNoThe callback function for a successful API call.
failfunctionNoThe callback function for a failed API call.
completefunctionNoThe callback function for the completion of the API call (executed for both successful and failed calls).

object.success Callback Function

Parameters

Object res

AttributeTypeDescription
responsestringInformation from the server.
successstringtrue if successful.

object.fail Callback Function

Parameters

Object res

AttributeTypeDescription
errCodestringError code.
errMsgstringError message.
successstringfalse if failed.

errMsg Explanation

Error MessageDescription
UploadFile fail, url is not startsWith http:U001Upload failed, invalid URL.
UploadFile fail, Exception_"+t.toString()+":U002Upload failed, an exception occurred.
UploadFile fail, file:" + localPath + " is not exist:U003Upload failed, the file address to upload doesn't exist.
UploadFile fail, parse: header/formData error:U004Upload failed, there's an error in header or formData.
UploadFile fail, onFailure_${e.toString()}:U005Upload failed.
UploadFile fail, onResponse_${e.toString()}:U006Upload failed.

Sample Code

// pages/index/index.js

Page({
uploadFile() {
dlt.uploadFile({
url: "xxx",
filePath: tempFilePaths[0],
formData: {
user: "test",
},
success(res) {
console.log(res);
},
fail(res) {
console.error(res);
},
});
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.