API | Description |
|---|---|
Uploads local resources to the server. | |
Listens for upload progress changes. | |
Stops listening for upload progress change events. | |
Suspends an upload task. |
Uploads local resources to the server. The client sends an HTTPS POST request, with content-type set to multipart/form-data.
Parameter | Type | Mandatory | Description |
|---|---|---|---|
url | string | Yes | Address of your server. |
filePath | string | Yes | Path of the file to be uploaded. |
name | string | Yes | Key of a file. You can use this key on the server to obtain the file's binary content. |
header | object | No | Header of an HTTP request. The header cannot contain a referer. |
formData | object | No | Additional form data in an HTTP request. |
success | function(object res) | No | Callback function triggered upon a successful API call. |
fail | function | No | Callback function triggered upon a failed API call. |
complete | function | No | If a function is passed, it will be called regardless of whether the API call succeeds or fails. |
Parameter | Type | Description |
|---|---|---|
data | string | Data returned by your server. |
statusCode | number | HTTP status code returned by your server. |
onClickUploadFile(event) {
const that = this
console.log("on onClickUploadFile" + qg.env.USER_DATA_PATH);
let cb = {
url:'https://testuploadurl.html', //your test url
filePath:'proto-file://usr/video_file.mp4',
name:'_file',
success(res) {
console.log("on onClickUploadFile: success : " + JSON.stringify(res));
that.uploadResponse.string = "Success:" + JSON.stringify(res)
},
fail(e) {
console.log("on onClickUploadFile: fail : " + JSON.stringify(e));
that.uploadResponse.string = "Fail:" + JSON.stringify(e)
},
complete() {
console.log("on onClickUploadFile: complete");
}
};
this.uploadTask = qg.uploadFile(cb);
this.progressFunc = function(res){
console.log("Receive upload progress cp callback = " + JSON.stringify(res))
that.uploadProgress.string = "Upload progress:" + res.progress
}
this.uploadTask.onProgressUpdate(this.progressFunc)
} Parameter | Type | Mandatory | Description |
|---|---|---|---|
callback | function | Yes | Callback function for upload progress change events. |
Parameter | Type | Description |
|---|---|---|
progress | number | Upload progress, in percentage. |
totalBytesSent | number | Size of the uploaded data, in bytes. |
totalBytesExpectedToSend | number | Anticipated total size of data to be uploaded, in bytes. |
this.progressFunc = function(res){
console.log("Receive upload progress cp callback = " + JSON.stringify(res))
that.uploadProgress.string = "Upload progress:" + res.progress
}
this.uploadTask.onProgressUpdate(this.progressFunc)