From e491ac1357d271888e5ffa83491e54289738b788 Mon Sep 17 00:00:00 2001 From: lovechinamo Date: Fri, 27 May 2022 17:59:05 +0800 Subject: [PATCH 1/7] Signed-off-by: lovechinamo Changes to be committed: --- api/@ohos.request.d.ts | 1247 ++++++++++++++++++++++------------------ 1 file changed, 685 insertions(+), 562 deletions(-) diff --git a/api/@ohos.request.d.ts b/api/@ohos.request.d.ts index 38ddc06e5f..5240178782 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 Context from './application/Context'; /** * upload and download @@ -22,719 +23,841 @@ import { AsyncCallback } from './basic'; */ declare namespace request { - /** - * Bit flag indicating download is allowed when using the cellular network. - * @syscap SystemCapability.MiscServices.Download - * @since 6 - * @permission ohos.permission.INTERNET - */ - const NETWORK_MOBILE: number; - - /** - * Bit flag indicating download is allowed when using the WLAN. - * @syscap SystemCapability.MiscServices.Download - * @since 6 - * @permission ohos.permission.INTERNET - */ - const NETWORK_WIFI: number; - - /** - * Indicates that the download cannot be resumed for some temporary errors. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - */ - const ERROR_CANNOT_RESUME: number; - - /** - * Indicates that no storage device, such as an SD card, is found. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - */ - const ERROR_DEVICE_NOT_FOUND: number; - - /** - * Indicates that files to be downloaded already exist, and that the download session cannot overwrite the existing files. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - */ - const ERROR_FILE_ALREADY_EXISTS: number; - - /** - * Indicates that a file operation fails. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - */ - const ERROR_FILE_ERROR: number; - - /** - * Indicates that the HTTP transmission fails. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - */ - const ERROR_HTTP_DATA_ERROR: number; - - /** - * Indicates insufficient storage space. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - */ - const ERROR_INSUFFICIENT_SPACE: number; - - /** - * Indicates an error caused by too many network redirections. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - */ - const ERROR_TOO_MANY_REDIRECTS: number; - - /** - * Indicates an HTTP code that cannot be identified. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - */ - const ERROR_UNHANDLED_HTTP_CODE: number; - - /** - * Indicates an undefined error. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - */ - const ERROR_UNKNOWN: 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 - * @since 7 - * @permission ohos.permission.INTERNET - */ - const PAUSED_QUEUED_FOR_WIFI: number; - - /** - * Indicates that the download is paused for some reasons. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - */ - const PAUSED_UNKNOWN: number; - - /** - * Indicates that the download is paused due to a network problem, for example, network disconnection. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - */ - const PAUSED_WAITING_FOR_NETWORK: number; - - /** - * Indicates that a network error occurs, and the download session will be retried. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - */ - const PAUSED_WAITING_TO_RETRY: number; - - /** - * Indicates that the download session has failed and will not be retried. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - */ - const SESSION_FAILED: number; - - /** - * Indicates that the download session has been paused. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - */ - const SESSION_PAUSED: number; - - /** - * Indicates that the download session is being scheduled. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - */ - const SESSION_PENDING: number; - - /** - * Indicates that the download session is in progress. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - */ - const SESSION_RUNNING: number; - - /** - * Indicates that the download session is completed. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - */ - const SESSION_SUCCESSFUL: number; - - /** - * Starts a download session. - * @syscap SystemCapability.MiscServices.Download - * @since 6 - * @param config download config - * @param callback Indicate the callback function to receive DownloadTask. - * @permission ohos.permission.INTERNET - * @return - - */ - function download(config: DownloadConfig, callback: AsyncCallback): void; - - /** - * Starts a download session. - * @syscap SystemCapability.MiscServices.Download - * @since 6 - * @param config download config - * @permission ohos.permission.INTERNET - * @return - - */ - function download(config: DownloadConfig): Promise; - - /** - * Starts a upload session. - * @syscap SystemCapability.MiscServices.Upload - * @since 6 - * @param config upload config - * @param callback Indicate the callback function to receive UploadTask. - * @permission ohos.permission.INTERNET - * @return - - */ - function upload(config: UploadConfig, callback: AsyncCallback): void; - - /** - * Starts a upload session. - * @syscap SystemCapability.MiscServices.Upload - * @since 6 - * @param config upload config - * @permission ohos.permission.INTERNET - * @return - - */ - function upload(config: UploadConfig): Promise; - - /** - * DownloadConfig data Structure - * - * @name DownloadConfig - * @since 6 - * @syscap SystemCapability.MiscServices.Download - * @permission ohos.permission.INTERNET - */ - interface DownloadConfig { - /** - * Resource address. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - url: string; - /** - * Adds an HTTP or HTTPS header to be included with the download request. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - header?: Object; - /** - * Allows download under a metered connection. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - enableMetered?: boolean; - /** - * Allows download in a roaming network. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - enableRoaming?: boolean; - /** - * Sets the description of a download session. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - description?: string; - /** - * Sets the network type allowed for download. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - networkType?: number; - /** - * Sets the path for downloads. - * - * @since 7 - * @permission ohos.permission.INTERNET - */ - filePath?: string; - /** - * Sets a download session title. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - title?: string; - } - - /** - * DownloadInfo data Structure - * - * @name DownloadInfo - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - */ - interface DownloadInfo { - /** - * the description of a file to be downloaded. - * - * @since 7 - * @permission ohos.permission.INTERNET - */ - description: string; - /** - * the real-time downloads size (in bytes). - * - * @since 7 - * @permission ohos.permission.INTERNET - */ - downloadedBytes: number; - /** - * the ID of a file to be downloaded. - * - * @since 7 - * @permission ohos.permission.INTERNET - */ - downloadId: number; - /** - * a download failure cause, which can be any DownloadSession.ERROR_* constant. - * - * @since 7 - * @permission ohos.permission.INTERNET - */ - failedReason: number; +/** + * Bit flag indicating download is allowed when using the cellular network. + * @syscap SystemCapability.MiscServices.Download + * @since 6 + * @permission ohos.permission.INTERNET + */ + const NETWORK_MOBILE: number; + /** - * the name of a file to be downloaded. - * - * @since 7 - * @permission ohos.permission.INTERNET - */ - fileName: string; + * Bit flag indicating download is allowed when using the WLAN. + * @syscap SystemCapability.MiscServices.Download + * @since 6 + * @permission ohos.permission.INTERNET + */ + const NETWORK_WIFI: number; + /** - * the URI of a stored file. - * + * Indicates that the download cannot be resumed for some temporary errors. + * @syscap SystemCapability.MiscServices.Download * @since 7 * @permission ohos.permission.INTERNET */ - filePath: string; + const ERROR_CANNOT_RESUME: number; + /** - * the reason why a session is paused, which can be any DownloadSession.PAUSED_* constant. - * + * Indicates that no storage device, such as an SD card, is found. + * @syscap SystemCapability.MiscServices.Download * @since 7 * @permission ohos.permission.INTERNET */ - pausedReason: number; + const ERROR_DEVICE_NOT_FOUND: number; + /** - * the download status code, which can be any DownloadSession.SESSION_* constant. - * + * Indicates that files to be downloaded already exist, and that the download session cannot overwrite the existing files. + * @syscap SystemCapability.MiscServices.Download * @since 7 * @permission ohos.permission.INTERNET */ - status: number; + const ERROR_FILE_ALREADY_EXISTS: number; + /** - * the URI of files to be downloaded. - * + * Indicates that a file operation fails. + * @syscap SystemCapability.MiscServices.Download * @since 7 * @permission ohos.permission.INTERNET */ - targetURI: string; + const ERROR_FILE_ERROR: number; + /** - * the title of a file to be downloaded. - * + * Indicates that the HTTP transmission fails. + * @syscap SystemCapability.MiscServices.Download * @since 7 * @permission ohos.permission.INTERNET */ - downloadTitle: string; + const ERROR_HTTP_DATA_ERROR: number; + /** - * the total size of files to be downloaded (in bytes). - * + * Indicates insufficient storage space. + * @syscap SystemCapability.MiscServices.Download * @since 7 * @permission ohos.permission.INTERNET */ - downloadTotalBytes: number; - } + const ERROR_INSUFFICIENT_SPACE: number; - interface DownloadTask { /** - * Called when the current download session is in process. + * Indicates an error caused by too many network redirections. * @syscap SystemCapability.MiscServices.Download - * @since 6 - * @param type progress Indicates the download task progress. - * @param callback The callback function for the download progress change event - * receivedSize the length of downloaded data, in bytes - * totalSize he length of data expected to be downloaded, in bytes. + * @since 7 * @permission ohos.permission.INTERNET - * @return - */ - on(type: 'progress', callback: (receivedSize: number, totalSize: number) => void): void; + const ERROR_TOO_MANY_REDIRECTS: number; /** - * Called when the current download session is in process. + * Indicates an HTTP code that cannot be identified. * @syscap SystemCapability.MiscServices.Download - * @since 6 - * @param type progress Indicates the download task progress. - * @param callback The callback function for the download progress change event - * receivedSize the length of downloaded data, in bytes - * totalSize he length of data expected to be downloaded, in bytes. + * @since 7 * @permission ohos.permission.INTERNET - * @return - */ - off(type: 'progress', callback?: (receivedSize: number, totalSize: number) => void): void; + const ERROR_UNHANDLED_HTTP_CODE: number; /** - * Called when the current download session complete、pause or remove. + * Indicates an undefined error. * @syscap SystemCapability.MiscServices.Download * @since 7 - * @param type Indicates the download session event type - * complete: download task completed, - * pause: download task stopped, - * remove: download task deleted. - * @param callback The callback function for the download complete、pause or remove change event. * @permission ohos.permission.INTERNET - * @return - */ - on(type: 'complete' | 'pause' | 'remove', callback: () => void): void; + const ERROR_UNKNOWN: number; /** - * Called when the current download session complete、pause or remove. + * 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 * @since 7 - * @param type Indicates the download session event type - * complete: download task completed, - * pause: download task stopped, - * remove: download task deleted. - * @param callback The callback function for the download complete、pause or remove change event. * @permission ohos.permission.INTERNET - * @return - */ - off(type: 'complete' | 'pause' | 'remove', callback?: () => void): void; + const PAUSED_QUEUED_FOR_WIFI: number; /** - * Called when the current download session fails. + * Indicates that the download is paused for some reasons. * @syscap SystemCapability.MiscServices.Download * @since 7 - * @param type Indicates the download session type, fail: download task has failed. - * @param callback The callback function for the download fail change event - * err The error code for download task. * @permission ohos.permission.INTERNET - * @return - */ - on(type: 'fail', callback: (err: number) => void): void; + const PAUSED_UNKNOWN: number; /** - * Called when the current download session fails. + * Indicates that the download is paused due to a network problem, for example, network disconnection. * @syscap SystemCapability.MiscServices.Download * @since 7 - * @param type Indicates the download session type, fail: download task has failed. - * @param callback Indicate the callback function to receive err. - * err The error code for download task. * @permission ohos.permission.INTERNET - * @return - */ - off(type: 'fail', callback?: (err: number) => void): void; + const PAUSED_WAITING_FOR_NETWORK: number; /** - * Deletes a download session and the downloaded files. + * Indicates that a network error occurs, and the download session will be retried. * @syscap SystemCapability.MiscServices.Download - * @since 6 - * @param callback Indicates asynchronous invoking Result. + * @since 7 * @permission ohos.permission.INTERNET - * @return - */ - remove(callback: AsyncCallback): void; + const PAUSED_WAITING_TO_RETRY: number; /** - * Deletes a download session and the downloaded files. + * Indicates that the download session has failed and will not be retried. * @syscap SystemCapability.MiscServices.Download - * @since 6 + * @since 7 * @permission ohos.permission.INTERNET - * @return - */ - remove(): Promise; + const SESSION_FAILED: number; /** - * Pause a download session. + * Indicates that the download session has been paused. * @syscap SystemCapability.MiscServices.Download * @since 7 - * @param callback Indicates asynchronous invoking Result. * @permission ohos.permission.INTERNET - * @return - */ - pause(callback: AsyncCallback): void; + const SESSION_PAUSED: number; /** - * Pause a download session. + * Indicates that the download session is being scheduled. * @syscap SystemCapability.MiscServices.Download * @since 7 * @permission ohos.permission.INTERNET - * @return - */ - pause(): Promise; + const SESSION_PENDING: number; /** - * Resume a paused download session. + * Indicates that the download session is in progress. * @syscap SystemCapability.MiscServices.Download * @since 7 - * @param callback Indicates asynchronous invoking Result. * @permission ohos.permission.INTERNET - * @return - */ - resume(callback: AsyncCallback): void; + const SESSION_RUNNING: number; /** - * Resume a paused download session. + * Indicates that the download session is completed. * @syscap SystemCapability.MiscServices.Download * @since 7 * @permission ohos.permission.INTERNET - * @return - */ - resume(): Promise; + const SESSION_SUCCESSFUL: number; /** - * Queries download information of a session, which is defined in DownloadSession.DownloadInfo. + * Starts a download session. * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @param callback Indicate the callback function to receive download info. + * @since 6 + * @param config download config + * @param callback Indicate the callback function to receive DownloadTask. * @permission ohos.permission.INTERNET * @return - + * @FAModelOnly */ - query(callback: AsyncCallback): void; + function download(config: DownloadConfig, callback: AsyncCallback): void; /** - * Queries download information of a session, which is defined in DownloadSession.DownloadInfo. + * Starts a download session. * @syscap SystemCapability.MiscServices.Download - * @since 7 + * @since 9 + * @param context Indicates the application context. + * @param config download config + * @param callback Indicate the callback function to receive DownloadTask. * @permission ohos.permission.INTERNET * @return - */ - query(): Promise; + function download(context: Context, config: DownloadConfig, callback: AsyncCallback): void; /** - * Queries the MIME type of the download file. + * Starts a download session. * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @param callback Indicate the callback function to receive download file MIME type. + * @since 6 + * @param config download config * @permission ohos.permission.INTERNET * @return - + * @FAModelOnly */ - queryMimeType(callback: AsyncCallback): void; + function download(config: DownloadConfig): Promise; /** - * Queries the MIME type of the download file. + * Starts a download session. * @syscap SystemCapability.MiscServices.Download - * @since 7 + * @since 9 + * @param context Indicates the application context. + * @param config download config * @permission ohos.permission.INTERNET * @return - */ - queryMimeType(): Promise; - } - - /** - * File data Structure - * - * @name File - * @since 6 - * @syscap SystemCapability.MiscServices.Download - * @permission ohos.permission.INTERNET - */ - interface File { - /** - * When multipart is submitted, the file name in the request header. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - filename: string; - /** - * When multipart is submitted, the name of the form item. The default is file. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - name: string; - /** - * The local storage path of the file (please refer to the storage directory definition for path usage). - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - uri: string; - /** - * The content type of the file is obtained by default according to the suffix of the file name or path. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - type: string; - } - - /** - * RequestData data Structure - * - * @name RequestData - * @since 6 - * @syscap SystemCapability.MiscServices.Download - * @permission ohos.permission.INTERNET - */ - interface RequestData { - /** - * Represents the name of the form element. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - name: string; - /** - * Represents the value of the form element. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - value: string; - } - - /** - * UploadConfig data Structure - * - * @name UploadConfig - * @since 6 - * @syscap SystemCapability.MiscServices.Upload - * @permission ohos.permission.INTERNET - */ - interface UploadConfig { - /** - * Resource address. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - url: string; - /** - * Adds an HTTP or HTTPS header to be included with the upload request. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - header: Object; - /** - * Request method: POST, PUT. The default POST. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - method: string; - /** - * A list of files to be uploaded. Please use multipart/form-data to submit. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - files: Array; + function download(context: Context, config: DownloadConfig): Promise; + /** - * The requested form data. - * + * Starts a upload session. + * @syscap SystemCapability.MiscServices.Upload * @since 6 + * @param config upload config + * @param callback Indicate the callback function to receive UploadTask. * @permission ohos.permission.INTERNET + * @return - + * @FAModelOnly */ - data: Array; - } + function upload(config: UploadConfig, callback: AsyncCallback): void; - interface UploadTask { /** - * Called when the current upload session is in process. + * Starts a upload session. * @syscap SystemCapability.MiscServices.Upload - * @since 6 - * @param type progress Indicates the upload task progress. - * @param callback The callback function for the upload progress change event - * uploadedSize The length of uploaded data, in bytes - * totalSize The length of data expected to be uploaded, in bytes. + * @since 9 + * @param context Indicates the application context. + * @param config upload config + * @param callback Indicate the callback function to receive UploadTask. * @permission ohos.permission.INTERNET * @return - */ - on(type: 'progress', callback: (uploadedSize: number, totalSize: number) => void): void; + function upload(context: Context, config: UploadConfig, callback: AsyncCallback): void; /** - * Called when the current upload session is in process. + * Starts a upload session. * @syscap SystemCapability.MiscServices.Upload * @since 6 - * @param type progress Indicates the upload task progress. - * @param callback The callback function for the upload progress change event - * uploadedSize The length of uploaded data, in bytes - * totalSize The length of data expected to be uploaded, in bytes. + * @param config upload config * @permission ohos.permission.INTERNET * @return - + * @FAModelOnly */ - off(type: 'progress', callback?: (uploadedSize: number, totalSize: number) => void): void; + function upload(config: UploadConfig): Promise; /** - * Called when the header of the current upload session has been received. + * Starts a upload session. * @syscap SystemCapability.MiscServices.Upload - * @since 7 - * @param type headerReceive Indicates the upload task headed receive. - * @param callback The callback function for the HTTP Response Header event - * header HTTP Response Header returned by the developer server. + * @since 9 + * @param context Indicates the application context. + * @param config upload config * @permission ohos.permission.INTERNET * @return - */ - on(type: 'headerReceive', callback: (header: object) => void): void; + function upload(context: Context, config: UploadConfig): Promise; /** - * Called when the header of the current upload session has been received. - * @syscap SystemCapability.MiscServices.Upload + * DownloadConfig data Structure + * + * @name DownloadConfig + * @since 6 + * @syscap SystemCapability.MiscServices.Download + * @permission ohos.permission.INTERNET + */ + interface DownloadConfig { + /** + * Resource address. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + url: string; + /** + * Adds an HTTP or HTTPS header to be included with the download request. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + header?: Object; + /** + * Allows download under a metered connection. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + enableMetered?: boolean; + /** + * Allows download in a roaming network. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + enableRoaming?: boolean; + /** + * Sets the description of a download session. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + description?: string; + /** + * Sets the network type allowed for download. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + networkType?: number; + /** + * Sets the path for downloads. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + filePath?: string; + /** + * Sets a download session title. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + title?: string; + /** + * Whether to display the background + * + * @since 9 + * @permission ohos.permission.INTERNET + */ + background?: boolean; + } + + /** + * DownloadInfo data Structure + * + * @name DownloadInfo + * @syscap SystemCapability.MiscServices.Download * @since 7 - * @param type headerReceive Indicates the upload task headed receive. - * @param callback The callback function for the HTTP Response Header event - * header HTTP Response Header returned by the developer server. * @permission ohos.permission.INTERNET - * @return - */ - off(type: 'headerReceive', callback?: (header: object) => void): void; - - /** - * Deletes a upload session. - * @syscap SystemCapability.MiscServices.Upload + interface DownloadInfo { + /** + * the description of a file to be downloaded. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + description: string; + /** + * the real-time downloads size (in bytes). + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + downloadedBytes: number; + /** + * the ID of a file to be downloaded. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + downloadId: number; + /** + * a download failure cause, which can be any DownloadSession.ERROR_* constant. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + failedReason: number; + /** + * the name of a file to be downloaded. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + fileName: string; + /** + * the URI of a stored file. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + filePath: string; + /** + * the reason why a session is paused, which can be any DownloadSession.PAUSED_* constant. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + pausedReason: number; + /** + * the download status code, which can be any DownloadSession.SESSION_* constant. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + status: number; + /** + * the URI of files to be downloaded. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + targetURI: string; + /** + * the title of a file to be downloaded. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + downloadTitle: string; + /** + * the total size of files to be downloaded (in bytes). + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + downloadTotalBytes: number; + } + + interface DownloadTask { + /** + * Called when the current download session is in process. + * @syscap SystemCapability.MiscServices.Download + * @since 6 + * @param type progress Indicates the download task progress. + * @param callback The callback function for the download progress change event + * receivedSize the length of downloaded data, in bytes + * totalSize he length of data expected to be downloaded, in bytes. + * @permission ohos.permission.INTERNET + * @return - + */ + on(type: 'progress', callback: (receivedSize: number, totalSize: number) => void): void; + + /** + * Called when the current download session is in process. + * @syscap SystemCapability.MiscServices.Download + * @since 6 + * @param type progress Indicates the download task progress. + * @param callback The callback function for the download progress change event + * receivedSize the length of downloaded data, in bytes + * totalSize he length of data expected to be downloaded, in bytes. + * @permission ohos.permission.INTERNET + * @return - + */ + off(type: 'progress', callback?: (receivedSize: number, totalSize: number) => void): void; + + /** + * Called when the current download session complete、pause or remove. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @param type Indicates the download session event type + * complete: download task completed, + * pause: download task stopped, + * remove: download task deleted. + * @param callback The callback function for the download complete、pause or remove change event. + * @permission ohos.permission.INTERNET + * @return - + */ + on(type: 'complete' | 'pause' | 'remove', callback: () => void): void; + + /** + * Called when the current download session complete、pause or remove. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @param type Indicates the download session event type + * complete: download task completed, + * pause: download task stopped, + * remove: download task deleted. + * @param callback The callback function for the download complete、pause or remove change event. + * @permission ohos.permission.INTERNET + * @return - + */ + off(type: 'complete' | 'pause' | 'remove', callback?: () => void): void; + + /** + * Called when the current download session fails. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @param type Indicates the download session type, fail: download task has failed. + * @param callback The callback function for the download fail change event + * err The error code for download task. + * @permission ohos.permission.INTERNET + * @return - + */ + on(type: 'fail', callback: (err: number) => void): void; + + /** + * Called when the current download session fails. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @param type Indicates the download session type, fail: download task has failed. + * @param callback Indicate the callback function to receive err. + * err The error code for download task. + * @permission ohos.permission.INTERNET + * @return - + */ + off(type: 'fail', callback?: (err: number) => void): void; + + /** + * Deletes a download session and the downloaded files. + * @syscap SystemCapability.MiscServices.Download + * @since 6 + * @param callback Indicates asynchronous invoking Result. + * @permission ohos.permission.INTERNET + * @return - + */ + remove(callback: AsyncCallback): void; + + /** + * Deletes a download session and the downloaded files. + * @syscap SystemCapability.MiscServices.Download + * @since 6 + * @permission ohos.permission.INTERNET + * @return - + */ + remove(): Promise; + + /** + * Pause a download session. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @param callback Indicates asynchronous invoking Result. + * @permission ohos.permission.INTERNET + * @return - + */ + pause(callback: AsyncCallback): void; + + /** + * Pause a download session. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + * @return - + */ + pause(): Promise; + + /** + * Resume a paused download session. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @param callback Indicates asynchronous invoking Result. + * @permission ohos.permission.INTERNET + * @return - + */ + resume(callback: AsyncCallback): void; + + /** + * Resume a paused download session. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + * @return - + */ + resume(): Promise; + + /** + * Queries download information of a session, which is defined in DownloadSession.DownloadInfo. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @param callback Indicate the callback function to receive download info. + * @permission ohos.permission.INTERNET + * @return - + */ + query(callback: AsyncCallback): void; + + /** + * Queries download information of a session, which is defined in DownloadSession.DownloadInfo. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + * @return - + */ + query(): Promise; + + /** + * Queries the MIME type of the download file. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @param callback Indicate the callback function to receive download file MIME type. + * @permission ohos.permission.INTERNET + * @return - + */ + queryMimeType(callback: AsyncCallback): void; + + /** + * Queries the MIME type of the download file. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + * @return - + */ + queryMimeType(): Promise; + } + + /** + * File data Structure + * + * @name File * @since 6 - * @param callback Indicates asynchronous invoking Result. + * @syscap SystemCapability.MiscServices.Download * @permission ohos.permission.INTERNET - * @return - */ - remove(callback: AsyncCallback): void; - - /** - * Deletes a upload session. - * @syscap SystemCapability.MiscServices.Upload + interface File { + /** + * When multipart is submitted, the file name in the request header. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + filename: string; + /** + * When multipart is submitted, the name of the form item. The default is file. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + name: string; + /** + * The local storage path of the file (please refer to the storage directory definition for path usage). + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + uri: string; + /** + * The content type of the file is obtained by default according to the suffix of the file name or path. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + type: string; + } + + /** + * RequestData data Structure + * + * @name RequestData * @since 6 + * @syscap SystemCapability.MiscServices.Download * @permission ohos.permission.INTERNET - * @return - */ - remove(): Promise; - } + interface RequestData { + /** + * Represents the name of the form element. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + name: string; + /** + * Represents the value of the form element. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + value: string; + } + + /** + * UploadConfig data Structure + * + * @name UploadConfig + * @since 6 + * @syscap SystemCapability.MiscServices.Upload + * @permission ohos.permission.INTERNET + */ + interface UploadConfig { + /** + * Resource address. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + url: string; + /** + * Adds an HTTP or HTTPS header to be included with the upload request. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + header: Object; + /** + * Request method: POST, PUT. The default POST. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + method: string; + /** + * A list of files to be uploaded. Please use multipart/form-data to submit. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + files: Array; + /** + * The requested form data. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + data: Array; + /** + * Whether to display the background + * + * @since 9 + * @permission ohos.permission.INTERNET + */ + background?: boolean; + } + + interface UploadTask { + /** + * Called when the current upload session is in process. + * @syscap SystemCapability.MiscServices.Upload + * @since 6 + * @param type progress Indicates the upload task progress. + * @param callback The callback function for the upload progress change event + * uploadedSize The length of uploaded data, in bytes + * totalSize The length of data expected to be uploaded, in bytes. + * @permission ohos.permission.INTERNET + * @return - + */ + on(type: 'progress', callback: (uploadedSize: number, totalSize: number) => void): void; + + /** + * Called when the current upload session is in process. + * @syscap SystemCapability.MiscServices.Upload + * @since 6 + * @param type progress Indicates the upload task progress. + * @param callback The callback function for the upload progress change event + * uploadedSize The length of uploaded data, in bytes + * totalSize The length of data expected to be uploaded, in bytes. + * @permission ohos.permission.INTERNET + * @return - + */ + off(type: 'progress', callback?: (uploadedSize: number, totalSize: number) => void): void; + + /** + * Called when the header of the current upload session has been received. + * @syscap SystemCapability.MiscServices.Upload + * @since 7 + * @param type headerReceive Indicates the upload task headed receive. + * @param callback The callback function for the HTTP Response Header event + * header HTTP Response Header returned by the developer server. + * @permission ohos.permission.INTERNET + * @return - + */ + on(type: 'headerReceive', callback: (header: object) => void): void; + + /** + * Called when the header of the current upload session has been received. + * @syscap SystemCapability.MiscServices.Upload + * @since 7 + * @param type headerReceive Indicates the upload task headed receive. + * @param callback The callback function for the HTTP Response Header event + * header HTTP Response Header returned by the developer server. + * @permission ohos.permission.INTERNET + * @return - + */ + off(type: 'headerReceive', callback?: (header: object) => void): void; + + /** + * Deletes a upload session. + * @syscap SystemCapability.MiscServices.Upload + * @since 6 + * @param callback Indicates asynchronous invoking Result. + * @permission ohos.permission.INTERNET + * @return - + */ + remove(callback: AsyncCallback): void; + + /** + * Deletes a upload session. + * @syscap SystemCapability.MiscServices.Upload + * @since 6 + * @permission ohos.permission.INTERNET + * @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; - + -- Gitee From b25e3a7ed88ed2c274626bd838699b2aea0588a2 Mon Sep 17 00:00:00 2001 From: lovechinamo Date: Sat, 28 May 2022 09:18:20 +0800 Subject: [PATCH 2/7] Signed-off-by: lovechinamo Changes to be committed: --- api/@ohos.request.d.ts | 1350 ++++++++++++++++++++-------------------- 1 file changed, 675 insertions(+), 675 deletions(-) diff --git a/api/@ohos.request.d.ts b/api/@ohos.request.d.ts index 5240178782..b297cdc79a 100644 --- a/api/@ohos.request.d.ts +++ b/api/@ohos.request.d.ts @@ -23,840 +23,840 @@ import Context from './application/Context'; */ declare namespace request { -/** - * Bit flag indicating download is allowed when using the cellular network. - * @syscap SystemCapability.MiscServices.Download - * @since 6 - * @permission ohos.permission.INTERNET - */ - const NETWORK_MOBILE: number; - + /** + * Bit flag indicating download is allowed when using the cellular network. + * @syscap SystemCapability.MiscServices.Download + * @since 6 + * @permission ohos.permission.INTERNET + */ + const NETWORK_MOBILE: number; + + /** + * Bit flag indicating download is allowed when using the WLAN. + * @syscap SystemCapability.MiscServices.Download + * @since 6 + * @permission ohos.permission.INTERNET + */ + const NETWORK_WIFI: number; + + /** + * Indicates that the download cannot be resumed for some temporary errors. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + */ + const ERROR_CANNOT_RESUME: number; + + /** + * Indicates that no storage device, such as an SD card, is found. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + */ + const ERROR_DEVICE_NOT_FOUND: number; + + /** + * Indicates that files to be downloaded already exist, and that the download session cannot overwrite the existing files. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + */ + const ERROR_FILE_ALREADY_EXISTS: number; + + /** + * Indicates that a file operation fails. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + */ + const ERROR_FILE_ERROR: number; + + /** + * Indicates that the HTTP transmission fails. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + */ + const ERROR_HTTP_DATA_ERROR: number; + + /** + * Indicates insufficient storage space. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + */ + const ERROR_INSUFFICIENT_SPACE: number; + + /** + * Indicates an error caused by too many network redirections. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + */ + const ERROR_TOO_MANY_REDIRECTS: number; + + /** + * Indicates an HTTP code that cannot be identified. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + */ + const ERROR_UNHANDLED_HTTP_CODE: number; + + /** + * Indicates an undefined error. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + */ + const ERROR_UNKNOWN: 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 + * @since 7 + * @permission ohos.permission.INTERNET + */ + const PAUSED_QUEUED_FOR_WIFI: number; + + /** + * Indicates that the download is paused for some reasons. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + */ + const PAUSED_UNKNOWN: number; + + /** + * Indicates that the download is paused due to a network problem, for example, network disconnection. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + */ + const PAUSED_WAITING_FOR_NETWORK: number; + + /** + * Indicates that a network error occurs, and the download session will be retried. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + */ + const PAUSED_WAITING_TO_RETRY: number; + + /** + * Indicates that the download session has failed and will not be retried. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + */ + const SESSION_FAILED: number; + + /** + * Indicates that the download session has been paused. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + */ + const SESSION_PAUSED: number; + + /** + * Indicates that the download session is being scheduled. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + */ + const SESSION_PENDING: number; + + /** + * Indicates that the download session is in progress. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + */ + const SESSION_RUNNING: number; + + /** + * Indicates that the download session is completed. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + */ + const SESSION_SUCCESSFUL: number; + + /** + * Starts a download session. + * @syscap SystemCapability.MiscServices.Download + * @since 6 + * @param config download config + * @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 context Indicates the application context. + * @param config download config + * @param callback Indicate the callback function to receive DownloadTask. + * @permission ohos.permission.INTERNET + * @return - + */ + function download(context: Context, config: DownloadConfig, callback: AsyncCallback): void; + + /** + * Starts a download session. + * @syscap SystemCapability.MiscServices.Download + * @since 6 + * @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 context Indicates the application context. + * @param config download config + * @permission ohos.permission.INTERNET + * @return - + */ + function download(context: Context, config: DownloadConfig): Promise; + + /** + * Starts a upload session. + * @syscap SystemCapability.MiscServices.Upload + * @since 6 + * @param config upload config + * @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 context Indicates the application context. + * @param config upload config + * @param callback Indicate the callback function to receive UploadTask. + * @permission ohos.permission.INTERNET + * @return - + */ + function upload(context: Context, config: UploadConfig, callback: AsyncCallback): void; + + /** + * Starts a upload session. + * @syscap SystemCapability.MiscServices.Upload + * @since 6 + * @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 context Indicates the application context. + * @param config upload config + * @permission ohos.permission.INTERNET + * @return - + */ + function upload(context: Context, config: UploadConfig): Promise; + + /** + * DownloadConfig data Structure + * + * @name DownloadConfig + * @since 6 + * @syscap SystemCapability.MiscServices.Download + * @permission ohos.permission.INTERNET + */ + interface DownloadConfig { + /** + * Resource address. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + url: string; /** - * Bit flag indicating download is allowed when using the WLAN. - * @syscap SystemCapability.MiscServices.Download - * @since 6 - * @permission ohos.permission.INTERNET - */ - const NETWORK_WIFI: number; - + * Adds an HTTP or HTTPS header to be included with the download request. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + header?: Object; /** - * Indicates that the download cannot be resumed for some temporary errors. - * @syscap SystemCapability.MiscServices.Download + * Allows download under a metered connection. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + enableMetered?: boolean; + /** + * Allows download in a roaming network. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + enableRoaming?: boolean; + /** + * Sets the description of a download session. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + description?: string; + /** + * Sets the network type allowed for download. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + networkType?: number; + /** + * Sets the path for downloads. + * * @since 7 * @permission ohos.permission.INTERNET */ - const ERROR_CANNOT_RESUME: number; - + filePath?: string; /** - * Indicates that no storage device, such as an SD card, is found. - * @syscap SystemCapability.MiscServices.Download + * Sets a download session title. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + title?: string; + /** + * Whether to display the background + * + * @since 9 + * @permission ohos.permission.INTERNET + */ + background?: boolean; + } + + /** + * DownloadInfo data Structure + * + * @name DownloadInfo + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + */ + interface DownloadInfo { + /** + * the description of a file to be downloaded. + * * @since 7 * @permission ohos.permission.INTERNET */ - const ERROR_DEVICE_NOT_FOUND: number; - + description: string; /** - * Indicates that files to be downloaded already exist, and that the download session cannot overwrite the existing files. - * @syscap SystemCapability.MiscServices.Download + * the real-time downloads size (in bytes). + * * @since 7 * @permission ohos.permission.INTERNET */ - const ERROR_FILE_ALREADY_EXISTS: number; - + downloadedBytes: number; /** - * Indicates that a file operation fails. - * @syscap SystemCapability.MiscServices.Download + * the ID of a file to be downloaded. + * * @since 7 * @permission ohos.permission.INTERNET */ - const ERROR_FILE_ERROR: number; - + downloadId: number; /** - * Indicates that the HTTP transmission fails. - * @syscap SystemCapability.MiscServices.Download + * a download failure cause, which can be any DownloadSession.ERROR_* constant. + * * @since 7 * @permission ohos.permission.INTERNET */ - const ERROR_HTTP_DATA_ERROR: number; - + failedReason: number; /** - * Indicates insufficient storage space. - * @syscap SystemCapability.MiscServices.Download + * the name of a file to be downloaded. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + fileName: string; + /** + * the URI of a stored file. + * * @since 7 * @permission ohos.permission.INTERNET */ - const ERROR_INSUFFICIENT_SPACE: number; + filePath: string; + /** + * the reason why a session is paused, which can be any DownloadSession.PAUSED_* constant. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + pausedReason: number; + /** + * the download status code, which can be any DownloadSession.SESSION_* constant. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + status: number; + /** + * the URI of files to be downloaded. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + targetURI: string; + /** + * the title of a file to be downloaded. + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + downloadTitle: string; + /** + * the total size of files to be downloaded (in bytes). + * + * @since 7 + * @permission ohos.permission.INTERNET + */ + downloadTotalBytes: number; + } + interface DownloadTask { /** - * Indicates an error caused by too many network redirections. + * Called when the current download session is in process. * @syscap SystemCapability.MiscServices.Download - * @since 7 + * @since 6 + * @param type progress Indicates the download task progress. + * @param callback The callback function for the download progress change event + * receivedSize the length of downloaded data, in bytes + * totalSize he length of data expected to be downloaded, in bytes. * @permission ohos.permission.INTERNET + * @return - */ - const ERROR_TOO_MANY_REDIRECTS: number; + on(type: 'progress', callback: (receivedSize: number, totalSize: number) => void): void; /** - * Indicates an HTTP code that cannot be identified. + * Called when the current download session is in process. * @syscap SystemCapability.MiscServices.Download - * @since 7 + * @since 6 + * @param type progress Indicates the download task progress. + * @param callback The callback function for the download progress change event + * receivedSize the length of downloaded data, in bytes + * totalSize he length of data expected to be downloaded, in bytes. * @permission ohos.permission.INTERNET + * @return - */ - const ERROR_UNHANDLED_HTTP_CODE: number; + off(type: 'progress', callback?: (receivedSize: number, totalSize: number) => void): void; /** - * Indicates an undefined error. + * Called when the current download session complete、pause or remove. * @syscap SystemCapability.MiscServices.Download * @since 7 + * @param type Indicates the download session event type + * complete: download task completed, + * pause: download task stopped, + * remove: download task deleted. + * @param callback The callback function for the download complete、pause or remove change event. * @permission ohos.permission.INTERNET + * @return - */ - const ERROR_UNKNOWN: number; + on(type: 'complete' | 'pause' | 'remove', callback: () => void): void; /** - * 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. + * Called when the current download session complete、pause or remove. * @syscap SystemCapability.MiscServices.Download * @since 7 + * @param type Indicates the download session event type + * complete: download task completed, + * pause: download task stopped, + * remove: download task deleted. + * @param callback The callback function for the download complete、pause or remove change event. * @permission ohos.permission.INTERNET + * @return - */ - const PAUSED_QUEUED_FOR_WIFI: number; + off(type: 'complete' | 'pause' | 'remove', callback?: () => void): void; /** - * Indicates that the download is paused for some reasons. + * Called when the current download session fails. * @syscap SystemCapability.MiscServices.Download * @since 7 + * @param type Indicates the download session type, fail: download task has failed. + * @param callback The callback function for the download fail change event + * err The error code for download task. * @permission ohos.permission.INTERNET + * @return - */ - const PAUSED_UNKNOWN: number; + on(type: 'fail', callback: (err: number) => void): void; /** - * Indicates that the download is paused due to a network problem, for example, network disconnection. + * Called when the current download session fails. * @syscap SystemCapability.MiscServices.Download * @since 7 + * @param type Indicates the download session type, fail: download task has failed. + * @param callback Indicate the callback function to receive err. + * err The error code for download task. * @permission ohos.permission.INTERNET + * @return - */ - const PAUSED_WAITING_FOR_NETWORK: number; + off(type: 'fail', callback?: (err: number) => void): void; /** - * Indicates that a network error occurs, and the download session will be retried. + * Deletes a download session and the downloaded files. * @syscap SystemCapability.MiscServices.Download - * @since 7 + * @since 6 + * @param callback Indicates asynchronous invoking Result. * @permission ohos.permission.INTERNET + * @return - */ - const PAUSED_WAITING_TO_RETRY: number; + remove(callback: AsyncCallback): void; /** - * Indicates that the download session has failed and will not be retried. + * Deletes a download session and the downloaded files. * @syscap SystemCapability.MiscServices.Download - * @since 7 + * @since 6 * @permission ohos.permission.INTERNET + * @return - */ - const SESSION_FAILED: number; + remove(): Promise; /** - * Indicates that the download session has been paused. + * Pause a download session. * @syscap SystemCapability.MiscServices.Download * @since 7 + * @param callback Indicates asynchronous invoking Result. * @permission ohos.permission.INTERNET + * @return - */ - const SESSION_PAUSED: number; + pause(callback: AsyncCallback): void; /** - * Indicates that the download session is being scheduled. + * Pause a download session. * @syscap SystemCapability.MiscServices.Download * @since 7 * @permission ohos.permission.INTERNET + * @return - */ - const SESSION_PENDING: number; + pause(): Promise; /** - * Indicates that the download session is in progress. + * Resume a paused download session. * @syscap SystemCapability.MiscServices.Download * @since 7 + * @param callback Indicates asynchronous invoking Result. * @permission ohos.permission.INTERNET + * @return - */ - const SESSION_RUNNING: number; + resume(callback: AsyncCallback): void; /** - * Indicates that the download session is completed. + * Resume a paused download session. * @syscap SystemCapability.MiscServices.Download * @since 7 * @permission ohos.permission.INTERNET + * @return - */ - const SESSION_SUCCESSFUL: number; + resume(): Promise; /** - * Starts a download session. + * Queries download information of a session, which is defined in DownloadSession.DownloadInfo. * @syscap SystemCapability.MiscServices.Download - * @since 6 - * @param config download config - * @param callback Indicate the callback function to receive DownloadTask. + * @since 7 + * @param callback Indicate the callback function to receive download info. * @permission ohos.permission.INTERNET * @return - - * @FAModelOnly */ - function download(config: DownloadConfig, callback: AsyncCallback): void; + query(callback: AsyncCallback): void; /** - * Starts a download session. + * Queries download information of a session, which is defined in DownloadSession.DownloadInfo. * @syscap SystemCapability.MiscServices.Download - * @since 9 - * @param context Indicates the application context. - * @param config download config - * @param callback Indicate the callback function to receive DownloadTask. + * @since 7 * @permission ohos.permission.INTERNET * @return - */ - function download(context: Context, config: DownloadConfig, callback: AsyncCallback): void; + query(): Promise; /** - * Starts a download session. + * Queries the MIME type of the download file. * @syscap SystemCapability.MiscServices.Download - * @since 6 - * @param config download config + * @since 7 + * @param callback Indicate the callback function to receive download file MIME type. * @permission ohos.permission.INTERNET * @return - - * @FAModelOnly */ - function download(config: DownloadConfig): Promise; + queryMimeType(callback: AsyncCallback): void; /** - * Starts a download session. + * Queries the MIME type of the download file. * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + * @return - + */ + queryMimeType(): Promise; + } + + /** + * File data Structure + * + * @name File + * @since 6 + * @syscap SystemCapability.MiscServices.Download + * @permission ohos.permission.INTERNET + */ + interface File { + /** + * When multipart is submitted, the file name in the request header. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + filename: string; + /** + * When multipart is submitted, the name of the form item. The default is file. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + name: string; + /** + * The local storage path of the file (please refer to the storage directory definition for path usage). + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + uri: string; + /** + * The content type of the file is obtained by default according to the suffix of the file name or path. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + type: string; + } + + /** + * RequestData data Structure + * + * @name RequestData + * @since 6 + * @syscap SystemCapability.MiscServices.Download + * @permission ohos.permission.INTERNET + */ + interface RequestData { + /** + * Represents the name of the form element. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + name: string; + /** + * Represents the value of the form element. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + value: string; + } + + /** + * UploadConfig data Structure + * + * @name UploadConfig + * @since 6 + * @syscap SystemCapability.MiscServices.Upload + * @permission ohos.permission.INTERNET + */ + interface UploadConfig { + /** + * Resource address. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + url: string; + /** + * Adds an HTTP or HTTPS header to be included with the upload request. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + header: Object; + /** + * Request method: POST, PUT. The default POST. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + method: string; + /** + * A list of files to be uploaded. Please use multipart/form-data to submit. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + files: Array; + /** + * The requested form data. + * + * @since 6 + * @permission ohos.permission.INTERNET + */ + data: Array; + /** + * Whether to display the background + * * @since 9 - * @param context Indicates the application context. - * @param config download config + * @permission ohos.permission.INTERNET + */ + background?: boolean; + } + + interface UploadTask { + /** + * Called when the current upload session is in process. + * @syscap SystemCapability.MiscServices.Upload + * @since 6 + * @param type progress Indicates the upload task progress. + * @param callback The callback function for the upload progress change event + * uploadedSize The length of uploaded data, in bytes + * totalSize The length of data expected to be uploaded, in bytes. * @permission ohos.permission.INTERNET * @return - */ - function download(context: Context, config: DownloadConfig): Promise; + on(type: 'progress', callback: (uploadedSize: number, totalSize: number) => void): void; /** - * Starts a upload session. + * Called when the current upload session is in process. * @syscap SystemCapability.MiscServices.Upload * @since 6 - * @param config upload config - * @param callback Indicate the callback function to receive UploadTask. + * @param type progress Indicates the upload task progress. + * @param callback The callback function for the upload progress change event + * uploadedSize The length of uploaded data, in bytes + * totalSize The length of data expected to be uploaded, in bytes. * @permission ohos.permission.INTERNET * @return - - * @FAModelOnly */ - function upload(config: UploadConfig, callback: AsyncCallback): void; + off(type: 'progress', callback?: (uploadedSize: number, totalSize: number) => void): void; /** - * Starts a upload session. + * Called when the header of the current upload session has been received. * @syscap SystemCapability.MiscServices.Upload - * @since 9 - * @param context Indicates the application context. - * @param config upload config - * @param callback Indicate the callback function to receive UploadTask. + * @since 7 + * @param type headerReceive Indicates the upload task headed receive. + * @param callback The callback function for the HTTP Response Header event + * header HTTP Response Header returned by the developer server. * @permission ohos.permission.INTERNET * @return - */ - function upload(context: Context, config: UploadConfig, callback: AsyncCallback): void; + on(type: 'headerReceive', callback: (header: object) => void): void; /** - * Starts a upload session. + * Called when the header of the current upload session has been received. * @syscap SystemCapability.MiscServices.Upload - * @since 6 - * @param config upload config + * @since 7 + * @param type headerReceive Indicates the upload task headed receive. + * @param callback The callback function for the HTTP Response Header event + * header HTTP Response Header returned by the developer server. * @permission ohos.permission.INTERNET * @return - - * @FAModelOnly */ - function upload(config: UploadConfig): Promise; + off(type: 'headerReceive', callback?: (header: object) => void): void; /** - * Starts a upload session. + * Deletes a upload session. * @syscap SystemCapability.MiscServices.Upload - * @since 9 - * @param context Indicates the application context. - * @param config upload config + * @since 6 + * @param callback Indicates asynchronous invoking Result. * @permission ohos.permission.INTERNET * @return - */ - function upload(context: Context, config: UploadConfig): Promise; + remove(callback: AsyncCallback): void; /** - * DownloadConfig data Structure - * - * @name DownloadConfig + * Deletes a upload session. + * @syscap SystemCapability.MiscServices.Upload * @since 6 - * @syscap SystemCapability.MiscServices.Download * @permission ohos.permission.INTERNET + * @return - */ - interface DownloadConfig { - /** - * Resource address. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - url: string; - /** - * Adds an HTTP or HTTPS header to be included with the download request. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - header?: Object; - /** - * Allows download under a metered connection. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - enableMetered?: boolean; - /** - * Allows download in a roaming network. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - enableRoaming?: boolean; - /** - * Sets the description of a download session. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - description?: string; - /** - * Sets the network type allowed for download. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - networkType?: number; - /** - * Sets the path for downloads. - * - * @since 7 - * @permission ohos.permission.INTERNET - */ - filePath?: string; - /** - * Sets a download session title. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - title?: string; - /** - * Whether to display the background - * - * @since 9 - * @permission ohos.permission.INTERNET - */ - background?: boolean; - } - - /** - * DownloadInfo data Structure - * - * @name DownloadInfo - * @syscap SystemCapability.MiscServices.Download - * @since 7 + 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 - */ - interface DownloadInfo { - /** - * the description of a file to be downloaded. - * - * @since 7 - * @permission ohos.permission.INTERNET - */ - description: string; - /** - * the real-time downloads size (in bytes). - * - * @since 7 - * @permission ohos.permission.INTERNET - */ - downloadedBytes: number; - /** - * the ID of a file to be downloaded. - * - * @since 7 - * @permission ohos.permission.INTERNET - */ - downloadId: number; - /** - * a download failure cause, which can be any DownloadSession.ERROR_* constant. - * - * @since 7 - * @permission ohos.permission.INTERNET - */ - failedReason: number; - /** - * the name of a file to be downloaded. - * - * @since 7 - * @permission ohos.permission.INTERNET - */ - fileName: string; - /** - * the URI of a stored file. - * - * @since 7 - * @permission ohos.permission.INTERNET - */ - filePath: string; - /** - * the reason why a session is paused, which can be any DownloadSession.PAUSED_* constant. - * - * @since 7 - * @permission ohos.permission.INTERNET - */ - pausedReason: number; - /** - * the download status code, which can be any DownloadSession.SESSION_* constant. - * - * @since 7 - * @permission ohos.permission.INTERNET - */ - status: number; - /** - * the URI of files to be downloaded. - * - * @since 7 - * @permission ohos.permission.INTERNET - */ - targetURI: string; - /** - * the title of a file to be downloaded. - * - * @since 7 - * @permission ohos.permission.INTERNET - */ - downloadTitle: string; - /** - * the total size of files to be downloaded (in bytes). - * - * @since 7 - * @permission ohos.permission.INTERNET - */ - downloadTotalBytes: number; - } - - interface DownloadTask { - /** - * Called when the current download session is in process. - * @syscap SystemCapability.MiscServices.Download - * @since 6 - * @param type progress Indicates the download task progress. - * @param callback The callback function for the download progress change event - * receivedSize the length of downloaded data, in bytes - * totalSize he length of data expected to be downloaded, in bytes. - * @permission ohos.permission.INTERNET - * @return - - */ - on(type: 'progress', callback: (receivedSize: number, totalSize: number) => void): void; - - /** - * Called when the current download session is in process. - * @syscap SystemCapability.MiscServices.Download - * @since 6 - * @param type progress Indicates the download task progress. - * @param callback The callback function for the download progress change event - * receivedSize the length of downloaded data, in bytes - * totalSize he length of data expected to be downloaded, in bytes. - * @permission ohos.permission.INTERNET - * @return - - */ - off(type: 'progress', callback?: (receivedSize: number, totalSize: number) => void): void; - - /** - * Called when the current download session complete、pause or remove. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @param type Indicates the download session event type - * complete: download task completed, - * pause: download task stopped, - * remove: download task deleted. - * @param callback The callback function for the download complete、pause or remove change event. - * @permission ohos.permission.INTERNET - * @return - - */ - on(type: 'complete' | 'pause' | 'remove', callback: () => void): void; - - /** - * Called when the current download session complete、pause or remove. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @param type Indicates the download session event type - * complete: download task completed, - * pause: download task stopped, - * remove: download task deleted. - * @param callback The callback function for the download complete、pause or remove change event. - * @permission ohos.permission.INTERNET - * @return - - */ - off(type: 'complete' | 'pause' | 'remove', callback?: () => void): void; - - /** - * Called when the current download session fails. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @param type Indicates the download session type, fail: download task has failed. - * @param callback The callback function for the download fail change event - * err The error code for download task. - * @permission ohos.permission.INTERNET - * @return - - */ - on(type: 'fail', callback: (err: number) => void): void; - - /** - * Called when the current download session fails. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @param type Indicates the download session type, fail: download task has failed. - * @param callback Indicate the callback function to receive err. - * err The error code for download task. - * @permission ohos.permission.INTERNET - * @return - - */ - off(type: 'fail', callback?: (err: number) => void): void; - - /** - * Deletes a download session and the downloaded files. - * @syscap SystemCapability.MiscServices.Download - * @since 6 - * @param callback Indicates asynchronous invoking Result. - * @permission ohos.permission.INTERNET - * @return - - */ - remove(callback: AsyncCallback): void; - - /** - * Deletes a download session and the downloaded files. - * @syscap SystemCapability.MiscServices.Download - * @since 6 - * @permission ohos.permission.INTERNET - * @return - - */ - remove(): Promise; - - /** - * Pause a download session. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @param callback Indicates asynchronous invoking Result. - * @permission ohos.permission.INTERNET - * @return - - */ - pause(callback: AsyncCallback): void; - - /** - * Pause a download session. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - * @return - - */ - pause(): Promise; - - /** - * Resume a paused download session. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @param callback Indicates asynchronous invoking Result. - * @permission ohos.permission.INTERNET - * @return - - */ - resume(callback: AsyncCallback): void; - - /** - * Resume a paused download session. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - * @return - - */ - resume(): Promise; - - /** - * Queries download information of a session, which is defined in DownloadSession.DownloadInfo. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @param callback Indicate the callback function to receive download info. - * @permission ohos.permission.INTERNET - * @return - - */ - query(callback: AsyncCallback): void; - - /** - * Queries download information of a session, which is defined in DownloadSession.DownloadInfo. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - * @return - - */ - query(): Promise; - - /** - * Queries the MIME type of the download file. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @param callback Indicate the callback function to receive download file MIME type. - * @permission ohos.permission.INTERNET - * @return - - */ - queryMimeType(callback: AsyncCallback): void; - - /** - * Queries the MIME type of the download file. - * @syscap SystemCapability.MiscServices.Download - * @since 7 - * @permission ohos.permission.INTERNET - * @return - - */ - queryMimeType(): Promise; - } - - /** - * File data Structure - * - * @name File - * @since 6 - * @syscap SystemCapability.MiscServices.Download + 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 - */ - interface File { - /** - * When multipart is submitted, the file name in the request header. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - filename: string; - /** - * When multipart is submitted, the name of the form item. The default is file. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - name: string; - /** - * The local storage path of the file (please refer to the storage directory definition for path usage). - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - uri: string; - /** - * The content type of the file is obtained by default according to the suffix of the file name or path. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - type: string; - } - - /** - * RequestData data Structure - * - * @name RequestData - * @since 6 - * @syscap SystemCapability.MiscServices.Download + 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 - */ - interface RequestData { - /** - * Represents the name of the form element. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - name: string; - /** - * Represents the value of the form element. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - value: string; - } + on(type: 'complete', callback: (code: Array, result?: Array) => void): void; /** - * UploadConfig data Structure - * - * @name UploadConfig - * @since 6 + * 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 - */ - interface UploadConfig { - /** - * Resource address. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - url: string; - /** - * Adds an HTTP or HTTPS header to be included with the upload request. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - header: Object; - /** - * Request method: POST, PUT. The default POST. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - method: string; - /** - * A list of files to be uploaded. Please use multipart/form-data to submit. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - files: Array; - /** - * The requested form data. - * - * @since 6 - * @permission ohos.permission.INTERNET - */ - data: Array; - /** - * Whether to display the background - * - * @since 9 - * @permission ohos.permission.INTERNET - */ - background?: boolean; - } - - interface UploadTask { - /** - * Called when the current upload session is in process. - * @syscap SystemCapability.MiscServices.Upload - * @since 6 - * @param type progress Indicates the upload task progress. - * @param callback The callback function for the upload progress change event - * uploadedSize The length of uploaded data, in bytes - * totalSize The length of data expected to be uploaded, in bytes. - * @permission ohos.permission.INTERNET - * @return - - */ - on(type: 'progress', callback: (uploadedSize: number, totalSize: number) => void): void; - - /** - * Called when the current upload session is in process. - * @syscap SystemCapability.MiscServices.Upload - * @since 6 - * @param type progress Indicates the upload task progress. - * @param callback The callback function for the upload progress change event - * uploadedSize The length of uploaded data, in bytes - * totalSize The length of data expected to be uploaded, in bytes. - * @permission ohos.permission.INTERNET - * @return - - */ - off(type: 'progress', callback?: (uploadedSize: number, totalSize: number) => void): void; - - /** - * Called when the header of the current upload session has been received. - * @syscap SystemCapability.MiscServices.Upload - * @since 7 - * @param type headerReceive Indicates the upload task headed receive. - * @param callback The callback function for the HTTP Response Header event - * header HTTP Response Header returned by the developer server. - * @permission ohos.permission.INTERNET - * @return - - */ - on(type: 'headerReceive', callback: (header: object) => void): void; - - /** - * Called when the header of the current upload session has been received. - * @syscap SystemCapability.MiscServices.Upload - * @since 7 - * @param type headerReceive Indicates the upload task headed receive. - * @param callback The callback function for the HTTP Response Header event - * header HTTP Response Header returned by the developer server. - * @permission ohos.permission.INTERNET - * @return - - */ - off(type: 'headerReceive', callback?: (header: object) => void): void; - - /** - * Deletes a upload session. - * @syscap SystemCapability.MiscServices.Upload - * @since 6 - * @param callback Indicates asynchronous invoking Result. - * @permission ohos.permission.INTERNET - * @return - - */ - remove(callback: AsyncCallback): void; - - /** - * Deletes a upload session. - * @syscap SystemCapability.MiscServices.Upload - * @since 6 - * @permission ohos.permission.INTERNET - * @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; - } + off(type: 'complete', callback?: (code: Array, result?: Array) => void): void; + } } export default request; -- Gitee From d55576fcd98799188cbe05e10fc74df5b62ab289 Mon Sep 17 00:00:00 2001 From: lovechinamo Date: Sat, 28 May 2022 17:18:34 +0800 Subject: [PATCH 3/7] Signed-off-by: lovechinamo Your branch is up to date with 'origin/master'. --- api/@ohos.request.d.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api/@ohos.request.d.ts b/api/@ohos.request.d.ts index b297cdc79a..fa6ccff793 100644 --- a/api/@ohos.request.d.ts +++ b/api/@ohos.request.d.ts @@ -111,6 +111,14 @@ declare namespace request { */ const ERROR_UNKNOWN: number; + /** + * Indicates that the network is offline. + * @syscap SystemCapability.MiscServices.Download + * @since 7 + * @permission ohos.permission.INTERNET + */ + const ERROR_NETWORK_ERROR: 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 -- Gitee From 8f0531345a2590745499d48d25c98853b09154df Mon Sep 17 00:00:00 2001 From: lovechinamo Date: Tue, 31 May 2022 19:44:11 +0800 Subject: [PATCH 4/7] Signed-off-by: lovechinamo Changes to be committed: --- api/@ohos.request.d.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/api/@ohos.request.d.ts b/api/@ohos.request.d.ts index fa6ccff793..4f823d34a1 100644 --- a/api/@ohos.request.d.ts +++ b/api/@ohos.request.d.ts @@ -13,7 +13,7 @@ * limitations under the License. */ import { AsyncCallback } from './basic'; -import Context from './application/Context'; +import BaseContext from './application/BaseContext'; /** * upload and download @@ -206,14 +206,14 @@ declare namespace request { /** * Starts a download session. * @syscap SystemCapability.MiscServices.Download - * @since 9 - * @param context Indicates the application context. + * @since 8 + * @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: Context, config: DownloadConfig, callback: AsyncCallback): void; + function download(BaseContext: BaseContext, config: DownloadConfig, callback: AsyncCallback): void; /** * Starts a download session. @@ -229,13 +229,13 @@ declare namespace request { /** * Starts a download session. * @syscap SystemCapability.MiscServices.Download - * @since 9 - * @param context Indicates the application context. + * @since 8 + * @param BaseContext Indicates the application BaseContext. * @param config download config * @permission ohos.permission.INTERNET * @return - */ - function download(context: Context, config: DownloadConfig): Promise; + function download(BaseContext: BaseContext, config: DownloadConfig): Promise; /** * Starts a upload session. @@ -252,14 +252,14 @@ declare namespace request { /** * Starts a upload session. * @syscap SystemCapability.MiscServices.Upload - * @since 9 - * @param context Indicates the application context. + * @since 8 + * @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: Context, config: UploadConfig, callback: AsyncCallback): void; + function upload(BaseContext: BaseContext, config: UploadConfig, callback: AsyncCallback): void; /** * Starts a upload session. @@ -275,13 +275,13 @@ declare namespace request { /** * Starts a upload session. * @syscap SystemCapability.MiscServices.Upload - * @since 9 - * @param context Indicates the application context. + * @since 8 + * @param BaseContext Indicates the application BaseContext. * @param config upload config * @permission ohos.permission.INTERNET * @return - */ - function upload(context: Context, config: UploadConfig): Promise; + function upload(BaseContext: BaseContext, config: UploadConfig): Promise; /** * DownloadConfig data Structure -- Gitee From fc9c10f8bd699c7ba1f57aaba8adf3672c5a97fd Mon Sep 17 00:00:00 2001 From: lovechinamo Date: Wed, 1 Jun 2022 15:30:23 +0800 Subject: [PATCH 5/7] Signed-off-by: lovechinamo Changes to be committed: --- api/@ohos.request.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api/@ohos.request.d.ts b/api/@ohos.request.d.ts index 4f823d34a1..1b2e0c2661 100644 --- a/api/@ohos.request.d.ts +++ b/api/@ohos.request.d.ts @@ -206,7 +206,7 @@ declare namespace request { /** * Starts a download session. * @syscap SystemCapability.MiscServices.Download - * @since 8 + * @since 9 * @param BaseContext Indicates the application BaseContext. * @param config download config * @param callback Indicate the callback function to receive DownloadTask. @@ -229,7 +229,7 @@ declare namespace request { /** * Starts a download session. * @syscap SystemCapability.MiscServices.Download - * @since 8 + * @since 9 * @param BaseContext Indicates the application BaseContext. * @param config download config * @permission ohos.permission.INTERNET @@ -252,7 +252,7 @@ declare namespace request { /** * Starts a upload session. * @syscap SystemCapability.MiscServices.Upload - * @since 8 + * @since 9 * @param BaseContext Indicates the application BaseContext. * @param config upload config * @param callback Indicate the callback function to receive UploadTask. @@ -275,7 +275,7 @@ declare namespace request { /** * Starts a upload session. * @syscap SystemCapability.MiscServices.Upload - * @since 8 + * @since 9 * @param BaseContext Indicates the application BaseContext. * @param config upload config * @permission ohos.permission.INTERNET -- Gitee From 64df76521ef58b915c1ab062ef0d9f74024f35de Mon Sep 17 00:00:00 2001 From: lovechinamo Date: Wed, 1 Jun 2022 17:28:12 +0800 Subject: [PATCH 6/7] Signed-off-by: lovechinamo Changes to be committed: --- api/@ohos.request.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/@ohos.request.d.ts b/api/@ohos.request.d.ts index 1b2e0c2661..91dfb8f417 100644 --- a/api/@ohos.request.d.ts +++ b/api/@ohos.request.d.ts @@ -114,10 +114,10 @@ declare namespace request { /** * Indicates that the network is offline. * @syscap SystemCapability.MiscServices.Download - * @since 7 + * @since 9 * @permission ohos.permission.INTERNET */ - const ERROR_NETWORK_ERROR: number; + const NETWORK_ERROR: 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. -- Gitee From 9a932b68d2f09aaa26d0dc5e59966cbcb1093ccb Mon Sep 17 00:00:00 2001 From: lovechinamo Date: Thu, 2 Jun 2022 10:33:41 +0800 Subject: [PATCH 7/7] Signed-off-by: lovechinamo Changes to be committed: --- api/@ohos.request.d.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api/@ohos.request.d.ts b/api/@ohos.request.d.ts index 91dfb8f417..52b41040ce 100644 --- a/api/@ohos.request.d.ts +++ b/api/@ohos.request.d.ts @@ -117,7 +117,7 @@ declare namespace request { * @since 9 * @permission ohos.permission.INTERNET */ - const NETWORK_ERROR: number; + 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. @@ -213,7 +213,7 @@ declare namespace request { * @permission ohos.permission.INTERNET * @return - */ - function download(BaseContext: BaseContext, config: DownloadConfig, callback: AsyncCallback): void; + function download(context: BaseContext, config: DownloadConfig, callback: AsyncCallback): void; /** * Starts a download session. @@ -235,7 +235,7 @@ declare namespace request { * @permission ohos.permission.INTERNET * @return - */ - function download(BaseContext: BaseContext, config: DownloadConfig): Promise; + function download(context: BaseContext, config: DownloadConfig): Promise; /** * Starts a upload session. @@ -259,7 +259,7 @@ declare namespace request { * @permission ohos.permission.INTERNET * @return - */ - function upload(BaseContext: BaseContext, config: UploadConfig, callback: AsyncCallback): void; + function upload(context: BaseContext, config: UploadConfig, callback: AsyncCallback): void; /** * Starts a upload session. @@ -281,7 +281,7 @@ declare namespace request { * @permission ohos.permission.INTERNET * @return - */ - function upload(BaseContext: BaseContext, config: UploadConfig): Promise; + function upload(context: BaseContext, config: UploadConfig): Promise; /** * DownloadConfig data Structure -- Gitee