• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Upload and Download Changelog
2
3## cl.request.1 Changes of Error Code Definitions and API Names
4
5- Processing of [error codes](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/errorcodes/errorcode-request.md) is added to the upload and download APIs.
6- Error information is returned via the **error** object in **AsyncCallback** or **Promise**. Wherein, parameter type or quantity error information is returned by throwing an exception.
7- Some APIs are replaced with new APIs, but the parameters remain unchanged.
8
9**Change Impact**
10
11The application developed based on earlier versions needs to adapt the method for returning API error information. Otherwise, the original service logic will be affected.
12
13**Key API/Component Changes**
14
15| Module         | Class          | Method/Attribute/Enum/Constant                                                                                                          | Change Type     |
16|--------------|--------------|-----------------------------------------------------------------------------------------------------------------------|-----------|
17| ohos.request | request      | EXCEPTION_PERMISSION                                                                                                  | Added|
18| ohos.request | request      | EXCEPTION_PARAMCHECK                                                                                                  | Added|
19| ohos.request | request      | EXCEPTION_UNSUPPORTED                                                                                                 | Added|
20| ohos.request | request      | EXCEPTION_FILEIO                                                                                                      | Added|
21| ohos.request | request      | EXCEPTION_FILEPATH                                                                                                    | Added|
22| ohos.request | request      | EXCEPTION_SERVICE                                                                                                     | Added|
23| ohos.request | request      | EXCEPTION_OTHERS                                                                                                      | Added|
24| ohos.request | request      | ERROR_OFFLINE                                                                                                         | Added|
25| ohos.request | request      | ERROR_UNSUPPORTED_NETWORK_TYPE                                                                                        | Added|
26| ohos.request | request      | function downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void;     | Added|
27| ohos.request | request      | function downloadFile(context: BaseContext, config: DownloadConfig): Promise<DownloadTask>;                           | Added|
28| ohos.request | request      | function uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback<UploadTask>): void;           | Added|
29| ohos.request | request      | function uploadFile(context: BaseContext, config: UploadConfig): Promise<UploadTask>;                                 | Added|
30| ohos.request | DownloadTask | delete(callback: AsyncCallback<boolean>): void;                                                                       | Added|
31| ohos.request | DownloadTask | delete(): Promise<boolean>;                                                                                           | Added|
32| ohos.request | DownloadTask | suspend(callback: AsyncCallback<boolean>): void;                                                                      | Added|
33| ohos.request | DownloadTask | suspend(): Promise<boolean>;                                                                                          | Added|
34| ohos.request | DownloadTask | restore(callback: AsyncCallback<boolean>): void;                                                                      | Added|
35| ohos.request | DownloadTask | restore(): Promise<boolean>;                                                                                          | Added|
36| ohos.request | DownloadTask | getTaskInfo(callback: AsyncCallback<DownloadInfo>): void;                                                             | Added|
37| ohos.request | DownloadTask | getTaskInfo(): Promise<DownloadInfo>;                                                                                 | Added|
38| ohos.request | DownloadTask | getTaskMimeType(callback: AsyncCallback<string>): void;                                                               | Added|
39| ohos.request | DownloadTask | getTaskMimeType(): Promise<string>;                                                                                   | Added|
40| ohos.request | UploadTask | delete(callback: AsyncCallback<boolean>): void;                                                                       | Added|
41| ohos.request | UploadTask | delete(): Promise<boolean>;                                                                                           | Added|
42| ohos.request | request      | function download(config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void;<br>Substitute API: function downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void;| Deprecated|
43| ohos.request | request      | function download(config: DownloadConfig): Promise<DownloadTask>;<br>Substitute API: function downloadFile(context: BaseContext, config: DownloadConfig): Promise<DownloadTask>; | Deprecated|
44| ohos.request | request      | function download(context: BaseContext, config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void;<br>Substitute API: function downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void;| Deprecated|
45| ohos.request | request      | function download(context: BaseContext, config: DownloadConfig): Promise<DownloadTask>;<br>Substitute API: function downloadFile(context: BaseContext, config: DownloadConfig): Promise<DownloadTask>; | Deprecated|
46| ohos.request | request      | function upload(config: UploadConfig, callback: AsyncCallback<UploadTask>): void;<br>Substitute API: function uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback<UploadTask>): void; | Deprecated|
47| ohos.request | request      | function upload(config: UploadConfig): Promise<UploadTask>;<br>Substitute API: function uploadFile(context: BaseContext, config: UploadConfig): Promise<UploadTask>; | Deprecated|
48| ohos.request | request      | function upload(context: BaseContext, config: UploadConfig, callback: AsyncCallback<UploadTask>): void;<br>Substitute API: function uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback<UploadTask>): void; | Deprecated|
49| ohos.request | request      | function upload(context: BaseContext, config: UploadConfig): Promise<UploadTask>;<br>Substitute API: function uploadFile(context: BaseContext, config: UploadConfig): Promise<UploadTask>; | Deprecated|
50| ohos.request | DownloadTask | remove(callback: AsyncCallback<boolean>): void;<br>Substitute API: delete(callback: AsyncCallback<boolean>): void                | Deprecated|
51| ohos.request | DownloadTask | remove(): Promise<boolean>;<br>Substitute API: delete(): Promise<boolean>;                                                       | Deprecated|
52| ohos.request | DownloadTask | pause(callback: AsyncCallback<boolean>): void;<br>Substitute API: suspend(callback: AsyncCallback<boolean>): void;               | Deprecated|
53| ohos.request | DownloadTask | pause(): Promise<boolean>;<br>Substitute API: suspend(): Promise<boolean>;                                                       | Deprecated|
54| ohos.request | DownloadTask | resume(callback: AsyncCallback<boolean>): void;<br>Substitute API: restore(callback: AsyncCallback<boolean>): void;              | Deprecated|
55| ohos.request | DownloadTask | resume(): Promise<boolean>;<br>Substitute API: restore(): Promise<boolean>;                                                      | Deprecated|
56| ohos.request | DownloadTask | query(callback: AsyncCallback<DownloadInfo>): void;<br>Substitute API: getTaskInfo(callback: AsyncCallback<DownloadInfo>): void; | Deprecated|
57| ohos.request | DownloadTask | query(): Promise<DownloadInfo>;<br>Substitute API: getTaskInfo(): Promise<DownloadInfo>;                                         | Deprecated|
58| ohos.request | DownloadTask | queryMimeType(callback: AsyncCallback<string>): void;<br>Substitute API: getTaskMimeType(callback: AsyncCallback<string>): void; | Deprecated|
59| ohos.request | DownloadTask | queryMimeType(): Promise<string>;<br>Substitute API: getTaskMimeType(): Promise<string>;                                         | Deprecated|
60| ohos.request | UploadTask | remove(callback: AsyncCallback<boolean>): void;<br>Substitute API: delete(callback: AsyncCallback<boolean>): void;               | Deprecated|
61| ohos.request | UploadTask | remove(): Promise<boolean>;<br>Substitute API: delete(): Promise<boolean>;                                                       | Deprecated|
62| system.request | UploadResponse | code                                                                                                                  | Deprecated|
63| system.request | UploadResponse | data                                                                                                                  | Deprecated|
64| system.request | UploadResponse | headers                                                                                                               | Deprecated|
65| system.request | DownloadResponse | token                                                                                                                 | Deprecated|
66| system.request | OnDownloadCompleteResponse | uri                                                                                                                   | Deprecated|
67| system.request | RequestFile | filename                                                                                                              | Deprecated|
68| system.request | RequestFile | name                                                                                                                  | Deprecated|
69| system.request | RequestFile | uri                                                                                                                   | Deprecated|
70| system.request | RequestFile | type                                                                                                                  | Deprecated|
71| system.request | RequestData | name                                                                                                                  | Deprecated|
72| system.request | RequestData | value                                                                                                                 | Deprecated|
73| system.request | UploadRequestOptions | url                                                                                                                   | Deprecated|
74| system.request | UploadRequestOptions | data                                                                                                                  | Deprecated|
75| system.request | UploadRequestOptions | files                                                                                                                 | Deprecated|
76| system.request | UploadRequestOptions | header                                                                                                                | Deprecated|
77| system.request | UploadRequestOptions | description                                                                                                           | Deprecated|
78| system.request | UploadRequestOptions | success                                                                                                               | Deprecated|
79| system.request | UploadRequestOptions | fail                                                                                                                  | Deprecated|
80| system.request | UploadRequestOptions | complete                                                                                                              | Deprecated|
81| system.request | OnDownloadCompleteOptions | token                                                                                                                 | Deprecated|
82| system.request | OnDownloadCompleteOptions | success                                                                                                               | Deprecated|
83| system.request | OnDownloadCompleteOptions | fail                                                                                                                  | Deprecated|
84| system.request | OnDownloadCompleteOptions | complete                                                                                                              | Deprecated|
85| system.request | Request | static upload(options: UploadRequestOptions): void;                                                                   | Deprecated|
86| system.request | Request | static download(options: DownloadRequestOptions): void;                                                               | Deprecated|
87| system.request | Request | static onDownloadComplete(options: OnDownloadCompleteOptions): void;                                                  | Deprecated|
88
89
90**Adaptation Guide**
91
92The following sample code shows how to call **downloadFile** in the new version:
93
94```ts
95try {
96    request.downloadFile(globalThis.abilityContext, { url: 'https://xxxx/xxxxx.hap',
97        filePath: 'xxx/xxxxx.hap'}, (err, data) => {
98        if (err) {
99            console.error('Failed to request the download. Cause: ' + JSON.stringify(err));
100            return;
101        }
102    });
103} catch (err) {
104    console.log("downloadFile callback fail." + "errCode:" + err.code + ",errMessage:" + err.message);
105}
106```
107