Upload and Download Changelog
cl.request.1 Changes of Error Code Definitions and API Names
- Processing of error codes is added to the upload and download APIs.
- 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.
- Some APIs are replaced with new APIs, but the parameters remain unchanged.
Change Impact
The application developed based on earlier versions needs to adapt the method for returning API error information. Otherwise, the original service logic will be affected.
Key API/Component Changes
Module | Class | Method/Attribute/Enum/Constant | Change Type |
---|---|---|---|
ohos.request | request | EXCEPTION_PERMISSION | Added |
ohos.request | request | EXCEPTION_PARAMCHECK | Added |
ohos.request | request | EXCEPTION_UNSUPPORTED | Added |
ohos.request | request | EXCEPTION_FILEIO | Added |
ohos.request | request | EXCEPTION_FILEPATH | Added |
ohos.request | request | EXCEPTION_SERVICE | Added |
ohos.request | request | EXCEPTION_OTHERS | Added |
ohos.request | request | ERROR_OFFLINE | Added |
ohos.request | request | ERROR_UNSUPPORTED_NETWORK_TYPE | Added |
ohos.request | request | function downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallback |
Added |
ohos.request | request | function downloadFile(context: BaseContext, config: DownloadConfig): Promise |
Added |
ohos.request | request | function uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback |
Added |
ohos.request | request | function uploadFile(context: BaseContext, config: UploadConfig): Promise |
Added |
ohos.request | DownloadTask | delete(callback: AsyncCallback |
Added |
ohos.request | DownloadTask | delete(): Promise |
Added |
ohos.request | DownloadTask | suspend(callback: AsyncCallback |
Added |
ohos.request | DownloadTask | suspend(): Promise |
Added |
ohos.request | DownloadTask | restore(callback: AsyncCallback |
Added |
ohos.request | DownloadTask | restore(): Promise |
Added |
ohos.request | DownloadTask | getTaskInfo(callback: AsyncCallback |
Added |
ohos.request | DownloadTask | getTaskInfo(): Promise |
Added |
ohos.request | DownloadTask | getTaskMimeType(callback: AsyncCallback |
Added |
ohos.request | DownloadTask | getTaskMimeType(): Promise |
Added |
ohos.request | UploadTask | delete(callback: AsyncCallback |
Added |
ohos.request | UploadTask | delete(): Promise |
Added |
ohos.request | request | function download(config: DownloadConfig, callback: AsyncCallback Substitute API: function downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallback |
Deprecated |
ohos.request | request | function download(config: DownloadConfig): Promise Substitute API: function downloadFile(context: BaseContext, config: DownloadConfig): Promise |
Deprecated |
ohos.request | request | function download(context: BaseContext, config: DownloadConfig, callback: AsyncCallback Substitute API: function downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallback |
Deprecated |
ohos.request | request | function download(context: BaseContext, config: DownloadConfig): Promise Substitute API: function downloadFile(context: BaseContext, config: DownloadConfig): Promise |
Deprecated |
ohos.request | request | function upload(config: UploadConfig, callback: AsyncCallback Substitute API: function uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback |
Deprecated |
ohos.request | request | function upload(config: UploadConfig): Promise Substitute API: function uploadFile(context: BaseContext, config: UploadConfig): Promise |
Deprecated |
ohos.request | request | function upload(context: BaseContext, config: UploadConfig, callback: AsyncCallback Substitute API: function uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback |
Deprecated |
ohos.request | request | function upload(context: BaseContext, config: UploadConfig): Promise Substitute API: function uploadFile(context: BaseContext, config: UploadConfig): Promise |
Deprecated |
ohos.request | DownloadTask | remove(callback: AsyncCallback Substitute API: delete(callback: AsyncCallback |
Deprecated |
ohos.request | DownloadTask | remove(): Promise Substitute API: delete(): Promise |
Deprecated |
ohos.request | DownloadTask | pause(callback: AsyncCallback Substitute API: suspend(callback: AsyncCallback |
Deprecated |
ohos.request | DownloadTask | pause(): Promise Substitute API: suspend(): Promise |
Deprecated |
ohos.request | DownloadTask | resume(callback: AsyncCallback Substitute API: restore(callback: AsyncCallback |
Deprecated |
ohos.request | DownloadTask | resume(): Promise Substitute API: restore(): Promise |
Deprecated |
ohos.request | DownloadTask | query(callback: AsyncCallback Substitute API: getTaskInfo(callback: AsyncCallback |
Deprecated |
ohos.request | DownloadTask | query(): Promise Substitute API: getTaskInfo(): Promise |
Deprecated |
ohos.request | DownloadTask | queryMimeType(callback: AsyncCallback Substitute API: getTaskMimeType(callback: AsyncCallback |
Deprecated |
ohos.request | DownloadTask | queryMimeType(): Promise Substitute API: getTaskMimeType(): Promise |
Deprecated |
ohos.request | UploadTask | remove(callback: AsyncCallback Substitute API: delete(callback: AsyncCallback |
Deprecated |
ohos.request | UploadTask | remove(): Promise Substitute API: delete(): Promise |
Deprecated |
system.request | UploadResponse | code | Deprecated |
system.request | UploadResponse | data | Deprecated |
system.request | UploadResponse | headers | Deprecated |
system.request | DownloadResponse | token | Deprecated |
system.request | OnDownloadCompleteResponse | uri | Deprecated |
system.request | RequestFile | filename | Deprecated |
system.request | RequestFile | name | Deprecated |
system.request | RequestFile | uri | Deprecated |
system.request | RequestFile | type | Deprecated |
system.request | RequestData | name | Deprecated |
system.request | RequestData | value | Deprecated |
system.request | UploadRequestOptions | url | Deprecated |
system.request | UploadRequestOptions | data | Deprecated |
system.request | UploadRequestOptions | files | Deprecated |
system.request | UploadRequestOptions | header | Deprecated |
system.request | UploadRequestOptions | description | Deprecated |
system.request | UploadRequestOptions | success | Deprecated |
system.request | UploadRequestOptions | fail | Deprecated |
system.request | UploadRequestOptions | complete | Deprecated |
system.request | OnDownloadCompleteOptions | token | Deprecated |
system.request | OnDownloadCompleteOptions | success | Deprecated |
system.request | OnDownloadCompleteOptions | fail | Deprecated |
system.request | OnDownloadCompleteOptions | complete | Deprecated |
system.request | Request | static upload(options: UploadRequestOptions): void; | Deprecated |
system.request | Request | static download(options: DownloadRequestOptions): void; | Deprecated |
system.request | Request | static onDownloadComplete(options: OnDownloadCompleteOptions): void; | Deprecated |
Adaptation Guide
The following sample code shows how to call downloadFile in the new version:
try {
request.downloadFile(globalThis.abilityContext, { url: 'https://xxxx/xxxxx.hap',
filePath: 'xxx/xxxxx.hap'}, (err, data) => {
if (err) {
console.error('Failed to request the download. Cause: ' + JSON.stringify(err));
return;
}
});
} catch (err) {
console.log("downloadFile callback fail." + "errCode:" + err.code + ",errMessage:" + err.message);
}