1# 上传下载子系统ChangeLog 2 3## cl.request.1 错误码定义及API部分接口名称变更 4 5- 新增上传下载接口的[错误码](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/errorcodes/errorcode-request.md)处理。 6- 错误信息通过AsyncCallback或Promise的error对象返回。其中,参数类型和数量错误信息,通过抛出异常的方式返回。 7- API部分接口需要用新的接口替换,参数不变。 8 9**变更影响** 10 11基于此前版本开发的应用,需适配变更后的新错误码和错误信息返回方式,否则会影响原有业务逻辑。 12 13**关键的接口/组件变更** 14 15| 模块名 | 类名 | 方法/属性/枚举/常量 | 变更类型 | 16|--------------|--------------|-----------------------------------------------------------------------------------------------------------------------|-----------| 17| ohos.request | request | EXCEPTION_PERMISSION | 新增 | 18| ohos.request | request | EXCEPTION_PARAMCHECK | 新增 | 19| ohos.request | request | EXCEPTION_UNSUPPORTED | 新增 | 20| ohos.request | request | EXCEPTION_FILEIO | 新增 | 21| ohos.request | request | EXCEPTION_FILEPATH | 新增 | 22| ohos.request | request | EXCEPTION_SERVICE | 新增 | 23| ohos.request | request | EXCEPTION_OTHERS | 新增 | 24| ohos.request | request | ERROR_OFFLINE | 新增 | 25| ohos.request | request | ERROR_UNSUPPORTED_NETWORK_TYPE | 新增 | 26| ohos.request | request | function downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void; | 新增 | 27| ohos.request | request | function downloadFile(context: BaseContext, config: DownloadConfig): Promise<DownloadTask>; | 新增 | 28| ohos.request | request | function uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback<UploadTask>): void; | 新增 | 29| ohos.request | request | function uploadFile(context: BaseContext, config: UploadConfig): Promise<UploadTask>; | 新增 | 30| ohos.request | DownloadTask | delete(callback: AsyncCallback<boolean>): void; | 新增 | 31| ohos.request | DownloadTask | delete(): Promise<boolean>; | 新增 | 32| ohos.request | DownloadTask | suspend(callback: AsyncCallback<boolean>): void; | 新增 | 33| ohos.request | DownloadTask | suspend(): Promise<boolean>; | 新增 | 34| ohos.request | DownloadTask | restore(callback: AsyncCallback<boolean>): void; | 新增 | 35| ohos.request | DownloadTask | restore(): Promise<boolean>; | 新增 | 36| ohos.request | DownloadTask | getTaskInfo(callback: AsyncCallback<DownloadInfo>): void; | 新增 | 37| ohos.request | DownloadTask | getTaskInfo(): Promise<DownloadInfo>; | 新增 | 38| ohos.request | DownloadTask | getTaskMimeType(callback: AsyncCallback<string>): void; | 新增 | 39| ohos.request | DownloadTask | getTaskMimeType(): Promise<string>; | 新增 | 40| ohos.request | UploadTask | delete(callback: AsyncCallback<boolean>): void; | 新增 | 41| ohos.request | UploadTask | delete(): Promise<boolean>; | 新增 | 42| ohos.request | request | function download(config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void;<br>代替接口:function downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void; | 废弃 | 43| ohos.request | request | function download(config: DownloadConfig): Promise<DownloadTask>;<br>代替接口:function downloadFile(context: BaseContext, config: DownloadConfig): Promise<DownloadTask>; | 废弃 | 44| ohos.request | request | function download(context: BaseContext, config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void;<br>代替接口:function downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void; | 废弃 | 45| ohos.request | request | function download(context: BaseContext, config: DownloadConfig): Promise<DownloadTask>;<br>代替接口:function downloadFile(context: BaseContext, config: DownloadConfig): Promise<DownloadTask>; | 废弃 | 46| ohos.request | request | function upload(config: UploadConfig, callback: AsyncCallback<UploadTask>): void;<br>代替接口:function uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback<UploadTask>): void; | 废弃 | 47| ohos.request | request | function upload(config: UploadConfig): Promise<UploadTask>;<br>代替接口:function uploadFile(context: BaseContext, config: UploadConfig): Promise<UploadTask>; | 废弃 | 48| ohos.request | request | function upload(context: BaseContext, config: UploadConfig, callback: AsyncCallback<UploadTask>): void;<br>代替接口:function uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback<UploadTask>): void; | 废弃 | 49| ohos.request | request | function upload(context: BaseContext, config: UploadConfig): Promise<UploadTask>;<br>代替接口:function uploadFile(context: BaseContext, config: UploadConfig): Promise<UploadTask>; | 废弃 | 50| ohos.request | DownloadTask | remove(callback: AsyncCallback<boolean>): void;<br>代替接口:delete(callback: AsyncCallback<boolean>): void | 废弃 | 51| ohos.request | DownloadTask | remove(): Promise<boolean>;<br>代替接口:delete(): Promise<boolean>; | 废弃 | 52| ohos.request | DownloadTask | pause(callback: AsyncCallback<boolean>): void;<br>代替接口:suspend(callback: AsyncCallback<boolean>): void; | 废弃 | 53| ohos.request | DownloadTask | pause(): Promise<boolean>;<br>代替接口:suspend(): Promise<boolean>; | 废弃 | 54| ohos.request | DownloadTask | resume(callback: AsyncCallback<boolean>): void;<br>代替接口:restore(callback: AsyncCallback<boolean>): void; | 废弃 | 55| ohos.request | DownloadTask | resume(): Promise<boolean>;<br>代替接口:restore(): Promise<boolean>; | 废弃 | 56| ohos.request | DownloadTask | query(callback: AsyncCallback<DownloadInfo>): void;<br>代替接口:getTaskInfo(callback: AsyncCallback<DownloadInfo>): void; | 废弃 | 57| ohos.request | DownloadTask | query(): Promise<DownloadInfo>;<br>代替接口:getTaskInfo(): Promise<DownloadInfo>; | 废弃 | 58| ohos.request | DownloadTask | queryMimeType(callback: AsyncCallback<string>): void;<br>代替接口:getTaskMimeType(callback: AsyncCallback<string>): void; | 废弃 | 59| ohos.request | DownloadTask | queryMimeType(): Promise<string>;<br>代替接口:getTaskMimeType(): Promise<string>; | 废弃 | 60| ohos.request | UploadTask | remove(callback: AsyncCallback<boolean>): void;<br>代替接口:delete(callback: AsyncCallback<boolean>): void; | 废弃 | 61| ohos.request | UploadTask | remove(): Promise<boolean>;<br>代替接口:delete(): Promise<boolean>; | 废弃 | 62| system.request | UploadResponse | code | 废弃 | 63| system.request | UploadResponse | data | 废弃 | 64| system.request | UploadResponse | headers | 废弃 | 65| system.request | DownloadResponse | token | 废弃 | 66| system.request | OnDownloadCompleteResponse | uri | 废弃 | 67| system.request | RequestFile | filename | 废弃 | 68| system.request | RequestFile | name | 废弃 | 69| system.request | RequestFile | uri | 废弃 | 70| system.request | RequestFile | type | 废弃 | 71| system.request | RequestData | name | 废弃 | 72| system.request | RequestData | value | 废弃 | 73| system.request | UploadRequestOptions | url | 废弃 | 74| system.request | UploadRequestOptions | data | 废弃 | 75| system.request | UploadRequestOptions | files | 废弃 | 76| system.request | UploadRequestOptions | header | 废弃 | 77| system.request | UploadRequestOptions | description | 废弃 | 78| system.request | UploadRequestOptions | success | 废弃 | 79| system.request | UploadRequestOptions | fail | 废弃 | 80| system.request | UploadRequestOptions | complete | 废弃 | 81| system.request | OnDownloadCompleteOptions | token | 废弃 | 82| system.request | OnDownloadCompleteOptions | success | 废弃 | 83| system.request | OnDownloadCompleteOptions | fail | 废弃 | 84| system.request | OnDownloadCompleteOptions | complete | 废弃 | 85| system.request | Request | static upload(options: UploadRequestOptions): void; | 废弃 | 86| system.request | Request | static download(options: DownloadRequestOptions): void; | 废弃 | 87| system.request | Request | static onDownloadComplete(options: OnDownloadCompleteOptions): void; | 废弃 | 88 89 90**适配指导** 91 92以downloadFile为例,在新版本上需要使用如下方式进行调用: 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```