未验证 提交 375d2d02 编写于 作者: O openharmony_ci 提交者: Gitee

!12804 修改文档

Merge pull request !12804 from ann_lesley/master
...@@ -112,11 +112,15 @@ uploadFile(context: BaseContext, config: UploadConfig): Promise<UploadTask&gt ...@@ -112,11 +112,15 @@ uploadFile(context: BaseContext, config: UploadConfig): Promise<UploadTask&gt
files: [{ filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" }], files: [{ filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" }],
data: [{ name: "name123", value: "123" }], data: [{ name: "name123", value: "123" }],
}; };
request.uploadFile(globalThis.abilityContext, uploadConfig).then((data) => { try {
request.uploadFile(globalThis.abilityContext, uploadConfig).then((data) => {
uploadTask = data; uploadTask = data;
}).catch((err) => { }).catch((err) => {
console.error('Failed to request the upload. Cause: ' + JSON.stringify(err)); console.error('Failed to request the upload. Cause: ' + JSON.stringify(err));
}); });
} catch (err) {
console.error('err.code : ' + err.code + ', err.message : ' + err.message);
}
``` ```
...@@ -156,13 +160,17 @@ uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback&l ...@@ -156,13 +160,17 @@ uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback&l
files: [{ filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" }], files: [{ filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" }],
data: [{ name: "name123", value: "123" }], data: [{ name: "name123", value: "123" }],
}; };
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data) => { try {
request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data) => {
if (err) { if (err) {
console.error('Failed to request the upload. Cause: ' + JSON.stringify(err)); console.error('Failed to request the upload. Cause: ' + JSON.stringify(err));
return; return;
} }
uploadTask = data; uploadTask = data;
}); });
} catch (err) {
console.error('err.code : ' + err.code + ', err.message : ' + err.message);
}
``` ```
## request.upload<sup>(deprecated)</sup> ## request.upload<sup>(deprecated)</sup>
...@@ -363,8 +371,8 @@ on(type: 'progress', callback:(uploadedSize: number, totalSize: number) =&gt; vo ...@@ -363,8 +371,8 @@ on(type: 'progress', callback:(uploadedSize: number, totalSize: number) =&gt; vo
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uploadedSize | number | 是 | 当前已上传文件大小,单位为KB。 | | uploadedSize | number | 是 | 当前已上传文件大小,单位为bit。 |
| totalSize | number | 是 | 上传文件的总大小,单位为KB。 | | totalSize | number | 是 | 上传文件的总大小,单位为bit。 |
**示例:** **示例:**
...@@ -472,8 +480,8 @@ off(type: 'progress', callback?: (uploadedSize: number, totalSize: number) =&g ...@@ -472,8 +480,8 @@ off(type: 'progress', callback?: (uploadedSize: number, totalSize: number) =&g
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uploadedSize | number | 是 | 当前已上传文件的大小,单位为KB。 | | uploadedSize | number | 是 | 当前已上传文件的大小,单位为bit。 |
| totalSize | number | 是 | 上传文件的总大小,单位为KB。 | | totalSize | number | 是 | 上传文件的总大小,单位为bit。 |
**示例:** **示例:**
...@@ -775,11 +783,15 @@ downloadFile(context: BaseContext, config: DownloadConfig): Promise&lt;DownloadT ...@@ -775,11 +783,15 @@ downloadFile(context: BaseContext, config: DownloadConfig): Promise&lt;DownloadT
```js ```js
let downloadTask; let downloadTask;
request.downloadFile(globalThis.abilityContext, { url: 'https://xxxx/xxxx.hap' }).then((data) => { try {
downloadTask = data; request.downloadFile(globalThis.abilityContext, { 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));
})
} catch (err) {
console.error('err.code : ' + err.code + ', err.message : ' + err.message);
}
``` ```
...@@ -814,14 +826,18 @@ downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallba ...@@ -814,14 +826,18 @@ downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallba
```js ```js
let downloadTask; let downloadTask;
request.downloadFile(globalThis.abilityContext, { url: 'https://xxxx/xxxxx.hap', try {
filePath: 'xxx/xxxxx.hap'}, (err, data) => { request.downloadFile(globalThis.abilityContext, { 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;
});
} catch (err) {
console.error('err.code : ' + err.code + ', err.message : ' + err.message);
}
``` ```
## request.download<sup>(deprecated)</sup> ## request.download<sup>(deprecated)</sup>
...@@ -995,8 +1011,8 @@ on(type: 'progress', callback:(receivedSize: number, totalSize: number) =&gt; vo ...@@ -995,8 +1011,8 @@ on(type: 'progress', callback:(receivedSize: number, totalSize: number) =&gt; vo
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| receivedSize | number | 是 | 当前下载的进度,单位为KB。 | | receivedSize | number | 是 | 当前下载的进度,单位为bit。 |
| totalSize | number | 是 | 下载文件的总大小,单位为KB。 | | totalSize | number | 是 | 下载文件的总大小,单位为bit。 |
**示例:** **示例:**
...@@ -1029,8 +1045,8 @@ off(type: 'progress', callback?: (receivedSize: number, totalSize: number) =&gt; ...@@ -1029,8 +1045,8 @@ off(type: 'progress', callback?: (receivedSize: number, totalSize: number) =&gt;
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| receivedSize | number | 是 | 当前下载的进度。 | | receivedSize | number | 是 | 当前下载的进度,单位为bit。 |
| totalSize | number | 是 | 下载文件的总大小。 | | totalSize | number | 是 | 下载文件的总大小,单位为bit。 |
**示例:** **示例:**
...@@ -1805,7 +1821,7 @@ resume(callback: AsyncCallback&lt;void&gt;): void ...@@ -1805,7 +1821,7 @@ resume(callback: AsyncCallback&lt;void&gt;): void
| enableMetered | boolean | 否 | 设置是否允许在按流量计费的连接下下载。<br/>-&nbsp;true:是<br/>-&nbsp;false:否 | | enableMetered | boolean | 否 | 设置是否允许在按流量计费的连接下下载。<br/>-&nbsp;true:是<br/>-&nbsp;false:否 |
| enableRoaming | boolean | 否 | 设置是否允许在漫游网络中下载。 <br/>-&nbsp;true:是<br/>-&nbsp;false:否| | enableRoaming | boolean | 否 | 设置是否允许在漫游网络中下载。 <br/>-&nbsp;true:是<br/>-&nbsp;false:否|
| description | string | 否 | 设置下载会话的描述。 | | description | string | 否 | 设置下载会话的描述。 |
| filePath<sup>7+</sup> | string | 否 | 设置下载路径(默认在'internal://cache/'路径下)。<br/>-&nbsp;filePath:'workspace/test.txt':默认路径下创建workspace路径,并将文件存储在workspace路径下。<br/>-&nbsp;filePath:'test.txt':将文件存储在默认路径下。<br/>-&nbsp;filePath:'workspace/':默认路径下创建workspace路径,并将文件存储在workspace路径下。 | | filePath<sup>7+</sup> | string | 否 | 设置下载路径<br/>-&nbsp;filePath:'/data/storage/el2/base/haps/entry/files/test.txt':将文件存储在绝对路径下。<br/>-&nbsp;FA模型下使用[context](js-apis-inner-app-context.md#contextgetcachedir) 获取应用存储路径,比如:'${featureAbility.getContext().getFilesDir()}/test.txt',并将文件存储在此路径下。<br/>-&nbsp;Stage模型下使用[AbilityContext](js-apis-inner-application-context.md) 类获取文件路径,比如:'${globalThis.abilityContext.tempDir}/test.txt'并将文件存储在此路径下。|
| networkType | number | 否 | 设置允许下载的网络类型。<br/>-&nbsp;NETWORK_MOBILE:0x00000001<br/>-&nbsp;NETWORK_WIFI:0x00010000| | networkType | number | 否 | 设置允许下载的网络类型。<br/>-&nbsp;NETWORK_MOBILE:0x00000001<br/>-&nbsp;NETWORK_WIFI:0x00010000|
| title | string | 否 | 设置下载会话标题。 | | title | string | 否 | 设置下载会话标题。 |
| background<sup>9+</sup> | boolean | 否 | 后台任务通知开关,开启后可在通知中显示下载状态。 | | background<sup>9+</sup> | boolean | 否 | 后台任务通知开关,开启后可在通知中显示下载状态。 |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册