• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 上传下载子系统ChangeLog
2
3
4## cl.request.2 request上传下载接口变更
5
6- 删除API9-beta接口:
71. function download(context: BaseContext, config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void;
82. function download(context: BaseContext, config: DownloadConfig): Promise<DownloadTask>;
93. function upload(context: BaseContext, config: UploadConfig, callback: AsyncCallback<UploadTask>): void;
104. function upload(context: BaseContext, config: UploadConfig): Promise<UploadTask>;
11
12**变更影响**
13
14基于此前版本使用Stage模式开发的应用,需适配变更后的接口,否则会影响原有业务逻辑。
15
16**关键的接口/组件变更**
17
18| 模块名          | 类名           | 方法/属性/枚举/常量                                                                                                       | 变更类型 |
19|--------------|--------------|-------------------------------------------------------------------------------------------------------------------|------|
20| ohos.request | request      | function download(context: BaseContext, config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void;     | 删除   |
21| ohos.request | request      | function download(context: BaseContext, config: DownloadConfig): Promise<DownloadTask>;                           | 删除   |
22| ohos.request | request      | function upload(context: BaseContext, config: UploadConfig, callback: AsyncCallback<UploadTask>): void;           | 删除   |
23| ohos.request | request      | function upload(context: BaseContext, config: UploadConfig): Promise<UploadTask>;                                 | 删除   |
24
25
26**适配指导**
27
28以download为例,在新版本上需要使用downloadFile, 如下方式进行调用:
29
30```ts
31try {
32    request.downloadFile(globalThis.abilityContext, { url: 'https://xxxx/xxxxx.hap',
33        filePath: 'xxx/xxxxx.hap'}, (err, data) => {
34        if (err) {
35            console.error('Failed to request the download. Cause: ' + JSON.stringify(err));
36            return;
37        }
38    });
39} catch (err) {
40    console.log("downloadFile callback fail." + "errCode:" + err.code + ",errMessage:" + err.message);
41}
42```