提交 5a8517a9 编写于 作者: E ester.zhou

update js-apis-request.md

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 b5db8417
# Upload and Download # Upload and Download
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. > **NOTE**<br>The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
## Modules to Import ## Modules to Import
...@@ -15,23 +14,23 @@ import request from '@ohos.request'; ...@@ -15,23 +14,23 @@ import request from '@ohos.request';
## Constraints ## Constraints
- HTTPS is supported by default. To support HTTP, you need to add **network** to the **config.json** file and set the **cleartextTraffic** attribute to **true**. HTTPS is supported by default. To support HTTP, you need to add **network** to the **config.json** file and set the **cleartextTraffic** attribute to **true**.
``` ```
"deviceConfig": { "deviceConfig": {
"default": { "default": {
"network": { "network": {
"cleartextTraffic": true "cleartextTraffic": true
}
...
} }
...
} }
``` }
```
## Constants ## Constants
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
...@@ -65,7 +64,7 @@ upload(config: UploadConfig): Promise&lt;UploadTask&gt; ...@@ -65,7 +64,7 @@ upload(config: UploadConfig): Promise&lt;UploadTask&gt;
Uploads files. This API uses a promise to return the result. Uploads files. This API uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload **System capability**: SystemCapability.MiscServices.Upload
...@@ -84,11 +83,13 @@ Uploads files. This API uses a promise to return the result. ...@@ -84,11 +83,13 @@ Uploads files. This API uses a promise to return the result.
**Example** **Example**
```js ```js
request.upload({ url: 'https://patch' }).then((data) => { let file1 = { filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" };
uploadTask = data; let uploadTask;
}).catch((err) => { request.upload({ url: 'https://patch', files: [file1] }).then((data) => {
console.error('Failed to request the upload. Cause: ' + JSON.stringify(err)); uploadTask = data;
}) }).catch((err) => {
console.error('Failed to request the upload. Cause: ' + JSON.stringify(err));
})
``` ```
...@@ -98,7 +99,7 @@ upload(config: UploadConfig, callback: AsyncCallback&lt;UploadTask&gt;): void ...@@ -98,7 +99,7 @@ upload(config: UploadConfig, callback: AsyncCallback&lt;UploadTask&gt;): void
Uploads files. This API uses an asynchronous callback to return the result. Uploads files. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload **System capability**: SystemCapability.MiscServices.Upload
...@@ -112,19 +113,21 @@ Uploads files. This API uses an asynchronous callback to return the result. ...@@ -112,19 +113,21 @@ Uploads files. This API uses an asynchronous callback to return the result.
**Example** **Example**
```js ```js
request.upload({ url: 'https://patch' }, (err, data) => { let file1 = { filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" };
if (err) { let uploadTask;
console.error('Failed to request the upload. Cause: ' + JSON.stringify(err)); request.upload({ url: 'https://patch', files: [file1] }, (err, data) => {
return; if (err) {
} console.error('Failed to request the upload. Cause: ' + JSON.stringify(err));
uploadTask = data; return;
}); }
uploadTask = data;
});
``` ```
## UploadTask ## UploadTask
Implements file uploads. Before using a method of this class, you must obtain an **UploadTask** object. Implements file uploads. Before using any APIs of this class, you must obtain an **UploadTask** object.
### on('progress') ### on('progress')
...@@ -133,7 +136,7 @@ on(type: 'progress', callback:(uploadedSize: number, totalSize: number) =&gt; vo ...@@ -133,7 +136,7 @@ on(type: 'progress', callback:(uploadedSize: number, totalSize: number) =&gt; vo
Subscribes to the upload progress event. This API uses an asynchronous callback to return the result. Subscribes to the upload progress event. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload **System capability**: SystemCapability.MiscServices.Upload
...@@ -154,10 +157,10 @@ Parameters of the callback function ...@@ -154,10 +157,10 @@ Parameters of the callback function
**Example** **Example**
```js ```js
uploadTask.on('progress', function callback(uploadedSize, totalSize) { uploadTask.on('progress', function callback(uploadedSize, totalSize) {
console.info("upload totalSize:" + totalSize + " uploadedSize:" + uploadedSize); console.info("upload totalSize:" + totalSize + " uploadedSize:" + uploadedSize);
} }
); );
``` ```
...@@ -167,7 +170,7 @@ on(type: 'headerReceive', callback: (header: object) =&gt; void): void ...@@ -167,7 +170,7 @@ on(type: 'headerReceive', callback: (header: object) =&gt; void): void
Subscribes to the **headerReceive** event, which is triggered when an HTTP response header is received. This API uses an asynchronous callback to return the result. Subscribes to the **headerReceive** event, which is triggered when an HTTP response header is received. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload **System capability**: SystemCapability.MiscServices.Upload
...@@ -187,10 +190,10 @@ Parameters of the callback function ...@@ -187,10 +190,10 @@ Parameters of the callback function
**Example** **Example**
```js ```js
uploadTask.on('headerReceive', function callback(headers){ uploadTask.on('headerReceive', function callback(headers){
console.info("upOnHeader headers:" + JSON.stringify(headers)); console.info("upOnHeader headers:" + JSON.stringify(headers));
} }
); );
``` ```
...@@ -200,7 +203,7 @@ off(type: 'progress', callback?: (uploadedSize: number, totalSize: number) =&g ...@@ -200,7 +203,7 @@ off(type: 'progress', callback?: (uploadedSize: number, totalSize: number) =&g
Unsubscribes from the upload progress event. This API uses an asynchronous callback to return the result. Unsubscribes from the upload progress event. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload **System capability**: SystemCapability.MiscServices.Upload
...@@ -221,10 +224,10 @@ Parameters of the callback function ...@@ -221,10 +224,10 @@ Parameters of the callback function
**Example** **Example**
```js ```js
uploadTask.off('progress', function callback(uploadedSize, totalSize) { uploadTask.off('progress', function callback(uploadedSize, totalSize) {
console.info('uploadedSize: ' + uploadedSize, 'totalSize: ' + totalSize); console.info('uploadedSize: ' + uploadedSize, 'totalSize: ' + totalSize);
} }
); );
``` ```
...@@ -234,7 +237,7 @@ off(type: 'headerReceive', callback?: (header: object) =&gt; void): void ...@@ -234,7 +237,7 @@ off(type: 'headerReceive', callback?: (header: object) =&gt; void): void
Unsubscribes from the **headerReceive** event. This API uses an asynchronous callback to return the result. Unsubscribes from the **headerReceive** event. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload **System capability**: SystemCapability.MiscServices.Upload
...@@ -254,10 +257,10 @@ Parameters of the callback function ...@@ -254,10 +257,10 @@ Parameters of the callback function
**Example** **Example**
```js ```js
uploadTask.off('headerReceive', function callback(headers) { uploadTask.off('headerReceive', function callback(headers) {
console.info("upOnHeader headers:" + JSON.stringify(headers)); console.info("upOnHeader headers:" + JSON.stringify(headers));
} }
); );
``` ```
...@@ -267,7 +270,7 @@ remove(): Promise&lt;boolean&gt; ...@@ -267,7 +270,7 @@ remove(): Promise&lt;boolean&gt;
Removes this upload task. This API uses a promise to return the result. Removes this upload task. This API uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload **System capability**: SystemCapability.MiscServices.Upload
...@@ -280,15 +283,15 @@ Removes this upload task. This API uses a promise to return the result. ...@@ -280,15 +283,15 @@ Removes this upload task. This API uses a promise to return the result.
**Example** **Example**
```js ```js
uploadTask.remove().then((result) => { uploadTask.remove().then((result) => {
if (result) { if (result) {
console.info('Upload task removed successfully. '); console.info('Upload task removed successfully. ');
} else { } else {
console.error('Failed to remove the upload task. '); console.error('Failed to remove the upload task. ');
} }
}).catch((err) => { }).catch((err) => {
console.error('Failed to remove the upload task. Cause: ' + JSON.stringify(err)); console.error('Failed to remove the upload task. Cause: ' + JSON.stringify(err));
}); });
``` ```
...@@ -298,7 +301,7 @@ remove(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -298,7 +301,7 @@ remove(callback: AsyncCallback&lt;boolean&gt;): void
Removes this upload task. This API uses an asynchronous callback to return the result. Removes this upload task. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload **System capability**: SystemCapability.MiscServices.Upload
...@@ -311,17 +314,17 @@ Removes this upload task. This API uses an asynchronous callback to return the r ...@@ -311,17 +314,17 @@ Removes this upload task. This API uses an asynchronous callback to return the r
**Example** **Example**
```js ```js
uploadTask.remove((err, result) => { uploadTask.remove((err, result) => {
if (err) { if (err) {
console.error('Failed to remove the upload task. Cause: ' + JSON.stringify(err)); console.error('Failed to remove the upload task. Cause: ' + JSON.stringify(err));
return; return;
} }
if (result) { if (result) {
console.info('Upload task removed successfully.'); console.info('Upload task removed successfully.');
} else { } else {
console.error('Failed to remove the upload task.'); console.error('Failed to remove the upload task.');
} }
}); });
``` ```
...@@ -366,7 +369,7 @@ download(config: DownloadConfig): Promise&lt;DownloadTask&gt; ...@@ -366,7 +369,7 @@ download(config: DownloadConfig): Promise&lt;DownloadTask&gt;
Downloads files. This API uses a promise to return the result. Downloads files. This API uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
...@@ -384,13 +387,14 @@ Downloads files. This API uses a promise to return the result. ...@@ -384,13 +387,14 @@ Downloads files. This API uses a promise to return the result.
**Example** **Example**
```js ```js
request.download({ url: 'https://xxxx/xxxx.hap' }).then((data) => { let downloadTask;
downloadTask = data; request.download({ url: 'https://xxxx/xxxx.hap' }).then((data) => {
}).catch((err) => { downloadTask = data;
console.error('Failed to request the download. Cause: ' + JSON.stringify(err)); }).catch((err) => {
}) console.error('Failed to request the download. Cause: ' + JSON.stringify(err));
``` })
```
## request.download ## request.download
...@@ -399,7 +403,7 @@ download(config: DownloadConfig, callback: AsyncCallback&lt;DownloadTask&gt;): v ...@@ -399,7 +403,7 @@ download(config: DownloadConfig, callback: AsyncCallback&lt;DownloadTask&gt;): v
Downloads files. This API uses an asynchronous callback to return the result. Downloads files. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
...@@ -413,14 +417,15 @@ Downloads files. This API uses an asynchronous callback to return the result. ...@@ -413,14 +417,15 @@ Downloads files. This API uses an asynchronous callback to return the result.
**Example** **Example**
```js ```js
request.download({ url: 'https://xxxx/xxxxx.hap', let downloadTask;
filePath: 'xxx/xxxxx.hap'}, (err, data) => { request.download({ url: 'https://xxxx/xxxxx.hap',
if (err) { filePath: 'xxx/xxxxx.hap'}, (err, data) => {
console.error('Failed to request the download. Cause: ' + JSON.stringify(err)); if (err) {
return; console.error('Failed to request the download. Cause: ' + JSON.stringify(err));
} return;
downloadTask = data; }
}); downloadTask = data;
});
``` ```
...@@ -435,7 +440,7 @@ on(type: 'progress', callback:(receivedSize: number, totalSize: number) =&gt; vo ...@@ -435,7 +440,7 @@ on(type: 'progress', callback:(receivedSize: number, totalSize: number) =&gt; vo
Subscribes to the download progress event. This API uses an asynchronous callback to return the result. Subscribes to the download progress event. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
...@@ -456,12 +461,6 @@ Parameters of the callback function ...@@ -456,12 +461,6 @@ Parameters of the callback function
**Example** **Example**
```js ```js
request.download({ url: 'https://xxxx/xxxx.hap' }, (err, data)=> {
if (err) {
console.error('Failed to request download. Cause:' + err);
return;
}
downloadTask = data;
downloadTask.on('progress', function download_callback(receivedSize, totalSize) { downloadTask.on('progress', function download_callback(receivedSize, totalSize) {
console.info("download receivedSize:" + receivedSize + " totalSize:" + totalSize); console.info("download receivedSize:" + receivedSize + " totalSize:" + totalSize);
} }
...@@ -476,7 +475,7 @@ off(type: 'progress', callback?: (receivedSize: number, totalSize: number) =&gt; ...@@ -476,7 +475,7 @@ off(type: 'progress', callback?: (receivedSize: number, totalSize: number) =&gt;
Unsubscribes from the download progress event. This API uses an asynchronous callback to return the result. Unsubscribes from the download progress event. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
...@@ -497,17 +496,11 @@ Parameters of the callback function ...@@ -497,17 +496,11 @@ Parameters of the callback function
**Example** **Example**
```js ```js
request.download({ url: 'https://xxxx/xxxx.hap' }, (err, data)=> { downloadTask .off('progress', function download_callback(receivedSize, totalSize) {
if (err) { console.info("download receivedSize:" + receivedSize + " totalSize:" + totalSize);
console.error('Failed to request download. Cause:' + err); }
return; );
} });
downloadTask = data;
downloadTask .off('progress', function download_callback(receivedSize, totalSize) {
console.info("download receivedSize:" + receivedSize + " totalSize:" + totalSize);
}
);
});
``` ```
...@@ -517,7 +510,7 @@ on(type: 'complete'|'pause'|'remove', callback:() =&gt; void): void ...@@ -517,7 +510,7 @@ on(type: 'complete'|'pause'|'remove', callback:() =&gt; void): void
Subscribes to a download event. This API uses an asynchronous callback to return the result. Subscribes to a download event. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
...@@ -531,17 +524,11 @@ Subscribes to a download event. This API uses an asynchronous callback to return ...@@ -531,17 +524,11 @@ Subscribes to a download event. This API uses an asynchronous callback to return
**Example** **Example**
```js ```js
request.download({ url: 'https://xxxx/xxxx.hap' }, (err, data)=> { downloadTask.on('complete', function callback() {
if (err) { console.info('Download task completed.');
console.error('Failed to request download. Cause:' + err); }
return; );
} });
downloadTask= data;
downloadTask.on('complete', function callback() {
console.info('Download task completed.');
}
);
});
``` ```
...@@ -551,7 +538,7 @@ off(type: 'complete'|'pause'|'remove', callback?:() =&gt; void): void ...@@ -551,7 +538,7 @@ off(type: 'complete'|'pause'|'remove', callback?:() =&gt; void): void
Unsubscribes from the download event. This API uses an asynchronous callback to return the result. Unsubscribes from the download event. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
...@@ -565,17 +552,11 @@ Unsubscribes from the download event. This API uses an asynchronous callback to ...@@ -565,17 +552,11 @@ Unsubscribes from the download event. This API uses an asynchronous callback to
**Example** **Example**
```js ```js
request.download({ url: 'https://xxxx/xxxx.hap' }, (err, data)=> { downloadTask.off('complete', function callback() {
if (err) { console.info('Download task completed.');
console.error('Failed to request download. Cause:' + JSON.stringify(err)); }
return; );
} });
downloadTask = data;
downloadTask.off('complete', function callback() {
console.info('Download task completed.');
}
);
});
``` ```
...@@ -585,7 +566,7 @@ on(type: 'fail', callback: (err: number) =&gt; void): void ...@@ -585,7 +566,7 @@ on(type: 'fail', callback: (err: number) =&gt; void): void
Subscribes to the download task failure event. This API uses an asynchronous callback to return the result. Subscribes to the download task failure event. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
...@@ -604,18 +585,12 @@ Parameters of the callback function ...@@ -604,18 +585,12 @@ Parameters of the callback function
**Example** **Example**
```js ```js
request.download({ url: 'https://xxxx/xxxx.hap' }, (err, data)=> { downloadTask.on('fail', function callBack(err) {
if (err) { console.info('Download task failed. Cause:' + err);
console.error('Failed to request download. Cause:' + err); }
return; );
} });
downloadTask = data;
downloadTask.on('fail', function callBack(err) {
console.info('Download task failed. Cause:' + err);
}
);
});
``` ```
...@@ -625,7 +600,7 @@ off(type: 'fail', callback?: (err: number) =&gt; void): void ...@@ -625,7 +600,7 @@ off(type: 'fail', callback?: (err: number) =&gt; void): void
Unsubscribes from the download task failure event. This API uses an asynchronous callback to return the result. Unsubscribes from the download task failure event. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
...@@ -645,12 +620,6 @@ Parameters of the callback function ...@@ -645,12 +620,6 @@ Parameters of the callback function
**Example** **Example**
```js ```js
request.download({ url: 'https://xxxx/xxxx.hap' }, (err, data)=> {
if (err) {
console.error('Failed to request download. Cause:' + err);
return;
}
downloadTask = data;
downloadTask.off('fail', function callBack(err) { downloadTask.off('fail', function callBack(err) {
console.info('Download task failed. Cause:' + err); console.info('Download task failed. Cause:' + err);
} }
...@@ -665,7 +634,7 @@ remove(): Promise&lt;boolean&gt; ...@@ -665,7 +634,7 @@ remove(): Promise&lt;boolean&gt;
Removes this download task. This API uses a promise to return the result. Removes this download task. This API uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
...@@ -696,7 +665,7 @@ remove(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -696,7 +665,7 @@ remove(callback: AsyncCallback&lt;boolean&gt;): void
Removes this download task. This API uses an asynchronous callback to return the result. Removes this download task. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
...@@ -709,17 +678,17 @@ Removes this download task. This API uses an asynchronous callback to return the ...@@ -709,17 +678,17 @@ Removes this download task. This API uses an asynchronous callback to return the
**Example** **Example**
```js ```js
downloadTask.remove((err, result)=>{ downloadTask.remove((err, result)=>{
if(err) { if(err) {
console.error('Failed to remove the download task.'); console.error('Failed to remove the download task.');
return; return;
} }
if (result) { if (result) {
console.info('Download task removed.'); console.info('Download task removed.');
} else { } else {
console.error('Failed to remove the download task.'); console.error('Failed to remove the download task.');
} }
}); });
``` ```
...@@ -729,7 +698,7 @@ query(): Promise&lt;DownloadInfo&gt; ...@@ -729,7 +698,7 @@ query(): Promise&lt;DownloadInfo&gt;
Queries this download task. This API uses a promise to return the result. Queries this download task. This API uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
...@@ -742,11 +711,11 @@ Queries this download task. This API uses a promise to return the result. ...@@ -742,11 +711,11 @@ Queries this download task. This API uses a promise to return the result.
**Example** **Example**
```js ```js
downloadTask.query().then((downloadInfo) => { downloadTask.query().then((downloadInfo) => {
console.info('Download task queried. Data:' + JSON.stringify(downloadInfo)) console.info('Download task queried. Data:' + JSON.stringify(downloadInfo))
}) .catch((err) => { }) .catch((err) => {
console.error('Failed to query the download task. Cause:' + err) console.error('Failed to query the download task. Cause:' + err)
}); });
``` ```
...@@ -756,7 +725,7 @@ query(callback: AsyncCallback&lt;DownloadInfo&gt;): void ...@@ -756,7 +725,7 @@ query(callback: AsyncCallback&lt;DownloadInfo&gt;): void
Queries this download task. This API uses an asynchronous callback to return the result. Queries this download task. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
...@@ -769,13 +738,13 @@ Queries this download task. This API uses an asynchronous callback to return the ...@@ -769,13 +738,13 @@ Queries this download task. This API uses an asynchronous callback to return the
**Example** **Example**
```js ```js
downloadTask.query((err, downloadInfo)=>{ downloadTask.query((err, downloadInfo)=>{
if(err) { if(err) {
console.error('Failed to query the download mimeType. Cause:' + JSON.stringify(err)); console.error('Failed to query the download mimeType. Cause:' + JSON.stringify(err));
} else { } else {
console.info('download query success. data:'+ JSON.stringify(downloadInfo)); console.info('download query success. data:'+ JSON.stringify(downloadInfo));
} }
}); });
``` ```
...@@ -785,7 +754,7 @@ queryMimeType(): Promise&lt;string&gt; ...@@ -785,7 +754,7 @@ queryMimeType(): Promise&lt;string&gt;
Queries **MimeType** of this download task. This API uses a promise to return the result. Queries **MimeType** of this download task. This API uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
...@@ -798,11 +767,11 @@ Queries **MimeType** of this download task. This API uses a promise to return th ...@@ -798,11 +767,11 @@ Queries **MimeType** of this download task. This API uses a promise to return th
**Example** **Example**
```js ```js
downloadTask.queryMimeType().then((data) => { downloadTask.queryMimeType().then((data) => {
console.info('Download task queried. Data:' + JSON.stringify(data)); console.info('Download task queried. Data:' + JSON.stringify(data));
}).catch((err) => { }).catch((err) => {
console.error('Failed to query the download MimeType. Cause:' + JSON.stringify(err)) console.error('Failed to query the download MimeType. Cause:' + JSON.stringify(err))
}); });
``` ```
...@@ -812,7 +781,7 @@ queryMimeType(callback: AsyncCallback&lt;string&gt;): void; ...@@ -812,7 +781,7 @@ queryMimeType(callback: AsyncCallback&lt;string&gt;): void;
Queries **MimeType** of this download task. This API uses an asynchronous callback to return the result. Queries **MimeType** of this download task. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
...@@ -825,13 +794,13 @@ Queries **MimeType** of this download task. This API uses an asynchronous callba ...@@ -825,13 +794,13 @@ Queries **MimeType** of this download task. This API uses an asynchronous callba
**Example** **Example**
```js ```js
downloadTask.queryMimeType((err, data)=>{ downloadTask.queryMimeType((err, data)=>{
if(err) { if(err) {
console.error('Failed to query the download mimeType. Cause:' + JSON.stringify(err)); console.error('Failed to query the download mimeType. Cause:' + JSON.stringify(err));
} else { } else {
console.info('Download task queried. data:' + JSON.stringify(data)); console.info('Download task queried. data:' + JSON.stringify(data));
} }
}); });
``` ```
...@@ -841,7 +810,7 @@ pause(): Promise&lt;void&gt; ...@@ -841,7 +810,7 @@ pause(): Promise&lt;void&gt;
Pauses this download task. This API uses a promise to return the result. Pauses this download task. This API uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
...@@ -854,15 +823,15 @@ Pauses this download task. This API uses a promise to return the result. ...@@ -854,15 +823,15 @@ Pauses this download task. This API uses a promise to return the result.
**Example** **Example**
```js ```js
downloadTask.pause().then((result) => { downloadTask.pause().then((result) => {
if (result) { if (result) {
console.info('Download task paused. '); console.info('Download task paused. ');
} else { } else {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(result)); console.error('Failed to pause the download task. Cause:' + JSON.stringify(result));
} }
}).catch((err) => { }).catch((err) => {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(err)); console.error('Failed to pause the download task. Cause:' + JSON.stringify(err));
}); });
``` ```
...@@ -872,7 +841,7 @@ pause(callback: AsyncCallback&lt;void&gt;): void ...@@ -872,7 +841,7 @@ pause(callback: AsyncCallback&lt;void&gt;): void
Pauses this download task. This API uses an asynchronous callback to return the result. Pauses this download task. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
...@@ -885,17 +854,17 @@ Pauses this download task. This API uses an asynchronous callback to return the ...@@ -885,17 +854,17 @@ Pauses this download task. This API uses an asynchronous callback to return the
**Example** **Example**
```js ```js
downloadTask.pause((err, result)=>{ downloadTask.pause((err, result)=>{
if(err) { if(err) {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(err)); console.error('Failed to pause the download task. Cause:' + JSON.stringify(err));
return; return;
} }
if (result) { if (result) {
console.info('Download task paused. '); console.info('Download task paused. ');
} else { } else {
console.error('Failed to pause the download task. Cause:' + JSON.stringify(result)); console.error('Failed to pause the download task. Cause:' + JSON.stringify(result));
} }
}); });
``` ```
...@@ -905,7 +874,7 @@ resume(): Promise&lt;void&gt; ...@@ -905,7 +874,7 @@ resume(): Promise&lt;void&gt;
Resumes this download task. This API uses a promise to return the result. Resumes this download task. This API uses a promise to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
...@@ -918,16 +887,16 @@ Resumes this download task. This API uses a promise to return the result. ...@@ -918,16 +887,16 @@ Resumes this download task. This API uses a promise to return the result.
**Example** **Example**
```js ```js
downloadTask.resume().then((result) => { downloadTask.resume().then((result) => {
if (result) { if (result) {
console.info('Download task resumed.') console.info('Download task resumed.')
} else { } else {
console.error('Failed to resume the download task. '); console.error('Failed to resume the download task. ');
} }
console.info('Download task resumed.') console.info('Download task resumed.')
}).catch((err) => { }).catch((err) => {
console.error('Failed to resume the download task. Cause:' + err); console.error('Failed to resume the download task. Cause:' + err);
}); });
``` ```
...@@ -937,7 +906,7 @@ resume(callback: AsyncCallback&lt;void&gt;): void ...@@ -937,7 +906,7 @@ resume(callback: AsyncCallback&lt;void&gt;): void
Resumes this download task. This API uses an asynchronous callback to return the result. Resumes this download task. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download **System capability**: SystemCapability.MiscServices.Download
...@@ -950,17 +919,17 @@ Resumes this download task. This API uses an asynchronous callback to return the ...@@ -950,17 +919,17 @@ Resumes this download task. This API uses an asynchronous callback to return the
**Example** **Example**
```js ```js
downloadTask.resume((err, result)=>{ downloadTask.resume((err, result)=>{
if (err) { if (err) {
console.error('Failed to resume the download task. Cause:' + err); console.error('Failed to resume the download task. Cause:' + err);
return; return;
} }
if (result) { if (result) {
console.info('Download task resumed.'); console.info('Download task resumed.');
} else { } else {
console.error('Failed to resume the download task.'); console.error('Failed to resume the download task.');
} }
}); });
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册