diff --git a/api/@ohos.request.d.ts b/api/@ohos.request.d.ts index 38ddc06e5f6f586caea9ec4d8814223feeac62c6..52b41040ce7330071b446113bdf7b1683ade077b 100644 --- a/api/@ohos.request.d.ts +++ b/api/@ohos.request.d.ts @@ -13,6 +13,7 @@ * limitations under the License. */ import { AsyncCallback } from './basic'; +import BaseContext from './application/BaseContext'; /** * upload and download @@ -110,6 +111,14 @@ declare namespace request { */ const ERROR_UNKNOWN: number; + /** + * Indicates that the network is offline. + * @syscap SystemCapability.MiscServices.Download + * @since 9 + * @permission ohos.permission.INTERNET + */ + const ERROR_NETWORK_FAIL: number; + /** * Indicates that the download is paused and waiting for a WLAN connection, because the file size exceeds the maximum allowed for a session using the cellular network. * @syscap SystemCapability.MiscServices.Download @@ -190,9 +199,22 @@ declare namespace request { * @param callback Indicate the callback function to receive DownloadTask. * @permission ohos.permission.INTERNET * @return - + * @FAModelOnly */ function download(config: DownloadConfig, callback: AsyncCallback): void; + /** + * Starts a download session. + * @syscap SystemCapability.MiscServices.Download + * @since 9 + * @param BaseContext Indicates the application BaseContext. + * @param config download config + * @param callback Indicate the callback function to receive DownloadTask. + * @permission ohos.permission.INTERNET + * @return - + */ + function download(context: BaseContext, config: DownloadConfig, callback: AsyncCallback): void; + /** * Starts a download session. * @syscap SystemCapability.MiscServices.Download @@ -200,9 +222,21 @@ declare namespace request { * @param config download config * @permission ohos.permission.INTERNET * @return - + * @FAModelOnly */ function download(config: DownloadConfig): Promise; + /** + * Starts a download session. + * @syscap SystemCapability.MiscServices.Download + * @since 9 + * @param BaseContext Indicates the application BaseContext. + * @param config download config + * @permission ohos.permission.INTERNET + * @return - + */ + function download(context: BaseContext, config: DownloadConfig): Promise; + /** * Starts a upload session. * @syscap SystemCapability.MiscServices.Upload @@ -211,9 +245,22 @@ declare namespace request { * @param callback Indicate the callback function to receive UploadTask. * @permission ohos.permission.INTERNET * @return - + * @FAModelOnly */ function upload(config: UploadConfig, callback: AsyncCallback): void; + /** + * Starts a upload session. + * @syscap SystemCapability.MiscServices.Upload + * @since 9 + * @param BaseContext Indicates the application BaseContext. + * @param config upload config + * @param callback Indicate the callback function to receive UploadTask. + * @permission ohos.permission.INTERNET + * @return - + */ + function upload(context: BaseContext, config: UploadConfig, callback: AsyncCallback): void; + /** * Starts a upload session. * @syscap SystemCapability.MiscServices.Upload @@ -221,9 +268,21 @@ declare namespace request { * @param config upload config * @permission ohos.permission.INTERNET * @return - + * @FAModelOnly */ function upload(config: UploadConfig): Promise; + /** + * Starts a upload session. + * @syscap SystemCapability.MiscServices.Upload + * @since 9 + * @param BaseContext Indicates the application BaseContext. + * @param config upload config + * @permission ohos.permission.INTERNET + * @return - + */ + function upload(context: BaseContext, config: UploadConfig): Promise; + /** * DownloadConfig data Structure * @@ -289,6 +348,13 @@ declare namespace request { * @permission ohos.permission.INTERNET */ title?: string; + /** + * Whether to display the background + * + * @since 9 + * @permission ohos.permission.INTERNET + */ + background?: boolean; } /** @@ -312,7 +378,7 @@ declare namespace request { * * @since 7 * @permission ohos.permission.INTERNET - */ + */ downloadedBytes: number; /** * the ID of a file to be downloaded. @@ -662,6 +728,13 @@ declare namespace request { * @permission ohos.permission.INTERNET */ data: Array; + /** + * Whether to display the background + * + * @since 9 + * @permission ohos.permission.INTERNET + */ + background?: boolean; } interface UploadTask { @@ -733,8 +806,66 @@ declare namespace request { * @return - */ remove(): Promise; + + /** + * Called when the current upload session fails. + * @syscap SystemCapability.MiscServices.Upload + * @since 9 + * @param type Indicates the Upload session type, fail: Upload task has failed. + * @param callback The callback function for the Upload fail change event + * err The error code for Upload task. + * @param The callback parameter result list corresponds to the server response after uploading + * each file in uploadconfig.files.Result is the server response body. If the server responds + * only once after uploading multiple files, there is only one element in the result list. + * @permission ohos.permission.INTERNET + * @return - + */ + on(type: 'fail', callback: (err: number, result?: Array) => void): void; + + /** + * Called when the current upload session fails. + * @syscap SystemCapability.MiscServices.Upload + * @since 9 + * @param type Indicates the upload session type, fail: upload task has failed. + * @param callback The callback function for the Upload fail change event err The error code + * for Upload task. + * @param The callback parameter result list corresponds to the server response after uploading + * each file in uploadconfig.files.Result is the server response body. If the server responds + * only once after uploading multiple files, there is only one element in the result list. + * @permission ohos.permission.INTERNET + * @return - + */ + off(type: 'fail', callback?: (err: number, result?: Array) => void): void; + + /** + * Called when the current upload session complete + * @syscap SystemCapability.MiscServices.Upload + * @since 9 + * @param type Indicates the upload session event type,complete: upload task completed, + * @param The callback parameter code/result list corresponds to the server response to + * each file uploaded in UploadConfig.files. Code is the server response code and result + * is the server response body. If the server responds only once after uploading + * multiple files, there is only one element in the code/result list. + * @permission ohos.permission.INTERNET + * @return - + */ + on(type: 'complete', callback: (code: Array, result?: Array) => void): void; + + /** + * Called when the current upload session complete + * @syscap SystemCapability.MiscServices.Upload + * @since 9 + * @param type Indicates the upload session event type,complete: upload task completed, + * @param The callback parameter code/result list corresponds to the server response to + * each file uploaded in UploadConfig.files. Code is the server response code and result + * is the server response body. If the server responds only once after uploading + * multiple files, there is only one element in the code/result list. + * @permission ohos.permission.INTERNET + * @return - + */ + off(type: 'complete', callback?: (code: Array, result?: Array) => void): void; } } export default request; - +