1 Star 0 Fork 99

Madi/axios

forked from OpenHarmony-SIG/ohos_axios 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
@ohos.request.d.ts 22.80 KB
一键复制 编辑 原始数据 按行查看 历史
MaDiXin 提交于 2022-08-10 19:12 . First commit
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { AsyncCallback } from './basic';
import BaseContext from './application/BaseContext';
/**
* upload and download
*
* @import request from '@ohos.request';
* @permission ohos.permission.INTERNET
*/
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 -
* @FAModelOnly
*/
function download(config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void;
/**
* Starts a download session.
* @syscap SystemCapability.MiscServices.Download
* @since 9
* @param BaseContext Indicates the application BaseContext.
* @param config download config
* @param callback Indicate the callback function to receive DownloadTask.
* @permission ohos.permission.INTERNET
* @return -
*/
function download(context: BaseContext, config: DownloadConfig, callback: AsyncCallback<DownloadTask>): 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<DownloadTask>;
/**
* Starts a download session.
* @syscap SystemCapability.MiscServices.Download
* @since 9
* @param BaseContext Indicates the application BaseContext.
* @param config download config
* @permission ohos.permission.INTERNET
* @return -
*/
function download(context: BaseContext, config: DownloadConfig): Promise<DownloadTask>;
/**
* 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<UploadTask>): void;
/**
* Starts a upload session.
* @syscap SystemCapability.MiscServices.Upload
* @since 9
* @param BaseContext Indicates the application BaseContext.
* @param config upload config
* @param callback Indicate the callback function to receive UploadTask.
* @permission ohos.permission.INTERNET
* @return -
*/
function upload(context: BaseContext, config: UploadConfig, callback: AsyncCallback<UploadTask>): 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<UploadTask>;
/**
* Starts a upload session.
* @syscap SystemCapability.MiscServices.Upload
* @since 9
* @param BaseContext Indicates the application BaseContext.
* @param config upload config
* @permission ohos.permission.INTERNET
* @return -
*/
function upload(context: BaseContext, config: UploadConfig): Promise<UploadTask>;
/**
* 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;
/**
* 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<boolean>): void;
/**
* Deletes a download session and the downloaded files.
* @syscap SystemCapability.MiscServices.Download
* @since 6
* @permission ohos.permission.INTERNET
* @return -
*/
remove(): Promise<boolean>;
/**
* 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>): void;
/**
* Pause a download session.
* @syscap SystemCapability.MiscServices.Download
* @since 7
* @permission ohos.permission.INTERNET
* @return -
*/
pause(): Promise<void>;
/**
* 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>): void;
/**
* Resume a paused download session.
* @syscap SystemCapability.MiscServices.Download
* @since 7
* @permission ohos.permission.INTERNET
* @return -
*/
resume(): Promise<void>;
/**
* 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<DownloadInfo>): 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<DownloadInfo>;
/**
* 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<string>): void;
/**
* Queries the MIME type of the download file.
* @syscap SystemCapability.MiscServices.Download
* @since 7
* @permission ohos.permission.INTERNET
* @return -
*/
queryMimeType(): Promise<string>;
}
/**
* 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<File>;
/**
* The requested form data.
*
* @since 6
* @permission ohos.permission.INTERNET
*/
data: Array<RequestData>;
}
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<boolean>): void;
/**
* Deletes a upload session.
* @syscap SystemCapability.MiscServices.Upload
* @since 6
* @permission ohos.permission.INTERNET
* @return -
*/
remove(): Promise<boolean>;
}
}
export default request;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/MaDiXin/axios.git
git@gitee.com:MaDiXin/axios.git
MaDiXin
axios
axios
master

搜索帮助