1/* 2 * Copyright (c) 2020 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @syscap SystemCapability.MiscServices.Upload 18 * @deprecated since 9, 19 * @useinstead ohos.request 20 */ 21export interface UploadResponse { 22 /** 23 * Status code returned by the server. 24 * @syscap SystemCapability.MiscServices.Upload 25 * @since 3 26 * @deprecated since 9 27 */ 28 code: number; 29 30 /** 31 * Content returned by the server. 32 * The value type is determined by the returned content. 33 * @syscap SystemCapability.MiscServices.Upload 34 * @since 3 35 * @deprecated since 9 36 */ 37 data: string; 38 39 /** 40 * Headers returned by the server. 41 * @syscap SystemCapability.MiscServices.Upload 42 * @since 3 43 * @deprecated since 9 44 */ 45 headers: Object; 46} 47 48/** 49 * @syscap SystemCapability.MiscServices.Download 50 * @deprecated since 9 51 */ 52export interface DownloadResponse { 53 /** 54 * Download token, which is used to obtain the download status. 55 * @syscap SystemCapability.MiscServices.Download 56 * @since 3 57 * @deprecated since 9 58 */ 59 token: string; 60} 61 62/** 63 * @syscap SystemCapability.MiscServices.Download 64 * @deprecated since 9 65 */ 66export interface OnDownloadCompleteResponse { 67 /** 68 * URI of the download file. 69 * @syscap SystemCapability.MiscServices.Download 70 * @since 3 71 * @deprecated since 9 72 */ 73 uri: string; 74} 75 76/** 77 * @syscap SystemCapability.MiscServices.Upload 78 * @deprecated since 9 79 */ 80export interface RequestFile { 81 /** 82 * File name in the header when multipart is used. 83 * @syscap SystemCapability.MiscServices.Upload 84 * @since 3 85 * @deprecated since 9 86 */ 87 filename?: string; 88 89 /** 90 * Name of a form item when multipart is used. The default value is file. 91 * @syscap SystemCapability.MiscServices.Upload 92 * @since 3 93 * @deprecated since 9 94 */ 95 name?: string; 96 97 /** 98 * Local storage directory of a file. 99 * @syscap SystemCapability.MiscServices.Upload 100 * @since 3 101 * @deprecated since 9 102 */ 103 uri: string; 104 105 /** 106 * Type of the file content. 107 * By default, the type is obtained based on the suffix of the file name or URI. 108 * @syscap SystemCapability.MiscServices.Upload 109 * @since 3 110 * @deprecated since 9 111 */ 112 type?: string; 113} 114 115/** 116 * @syscap SystemCapability.MiscServices.Upload 117 * @deprecated since 9 118 */ 119export interface RequestData { 120 /** 121 * Name of the form element. 122 * @syscap SystemCapability.MiscServices.Upload 123 * @since 3 124 * @deprecated since 9 125 */ 126 name: string; 127 128 /** 129 * Value of the form element. 130 * @syscap SystemCapability.MiscServices.Upload 131 * @since 3 132 * @deprecated since 9 133 */ 134 value: string; 135} 136 137/** 138 * @syscap SystemCapability.MiscServices.Upload 139 * @deprecated since 9 140 */ 141export interface UploadRequestOptions { 142 /** 143 * Resource URL. 144 * @syscap SystemCapability.MiscServices.Upload 145 * @since 3 146 * @deprecated since 9 147 */ 148 url: string; 149 150 /** 151 * Form data in the request body. 152 * @syscap SystemCapability.MiscServices.Upload 153 * @since 3 154 * @deprecated since 9 155 */ 156 data?: Array<RequestData>; 157 158 /** 159 * List of files to upload, which is submitted through multipart/form-data. 160 * @syscap SystemCapability.MiscServices.Upload 161 * @since 3 162 * @deprecated since 9 163 */ 164 files: Array<RequestFile>; 165 166 /** 167 * Request header. 168 * @syscap SystemCapability.MiscServices.Upload 169 * @since 3 170 * @deprecated since 9 171 */ 172 header?: Object; 173 174 /** 175 * Request methods available: POST and PUT. The default value is POST. 176 * @syscap SystemCapability.MiscServices.Upload 177 * @since 3 178 * @deprecated since 9 179 */ 180 method?: string; 181 182 /** 183 * Called when the files are uploaded successfully. 184 * @syscap SystemCapability.MiscServices.Upload 185 * @since 3 186 * @deprecated since 9 187 */ 188 success?: (data: UploadResponse) => void; 189 190 /** 191 * Called when uploading fails. 192 * @syscap SystemCapability.MiscServices.Upload 193 * @since 3 194 * @deprecated since 9 195 */ 196 fail?: (data: any, code: number) => void; 197 198 /** 199 * Called when the execution is completed. 200 * @syscap SystemCapability.MiscServices.Upload 201 * @since 3 202 * @deprecated since 9 203 */ 204 complete?: () => void; 205} 206 207/** 208 * @syscap SystemCapability.MiscServices.Download 209 * @deprecated since 9 210 */ 211export interface DownloadRequestOptions { 212 /** 213 * Resource URL. 214 * @syscap SystemCapability.MiscServices.Download 215 * @since 3 216 * @deprecated since 9 217 */ 218 url: string; 219 220 /** 221 * Name of the file to downloaded. 222 * The value is obtained from the current request or resource URL by default. 223 * @syscap SystemCapability.MiscServices.Download 224 * @since 3 225 * @deprecated since 9 226 */ 227 filename?: string; 228 229 /** 230 * Request header. 231 * @syscap SystemCapability.MiscServices.Download 232 * @since 3 233 * @deprecated since 9 234 */ 235 header?: string; 236 237 /** 238 * Download description. 239 * The default value is the file name. 240 * @syscap SystemCapability.MiscServices.Download 241 * @since 3 242 * @deprecated since 9 243 */ 244 description?: string; 245 246 /** 247 * Called when the files are successfully downloaded. 248 * @syscap SystemCapability.MiscServices.Download 249 * @since 3 250 * @deprecated since 9 251 */ 252 success?: (data: DownloadResponse) => void; 253 254 /** 255 * Called when downloading fails. 256 * @syscap SystemCapability.MiscServices.Download 257 * @since 3 258 * @deprecated since 9 259 */ 260 fail?: (data: any, code: number) => void; 261 262 /** 263 * Called when the execution is completed. 264 * @syscap SystemCapability.MiscServices.Download 265 * @since 3 266 * @deprecated since 9 267 */ 268 complete?: () => void; 269} 270 271/** 272 * @syscap SystemCapability.MiscServices.Download 273 * @deprecated since 9 274 */ 275export interface OnDownloadCompleteOptions { 276 /** 277 * Token of the result returned by the download function. 278 * @syscap SystemCapability.MiscServices.Download 279 * @since 3 280 * @deprecated since 9 281 */ 282 token: string; 283 284 /** 285 * Called when the downloads are successfully obtained 286 * @syscap SystemCapability.MiscServices.Download 287 * @since 3 288 * @deprecated since 9 289 */ 290 success?: (data: OnDownloadCompleteResponse) => void; 291 292 /** 293 * Called when the downloads fail to be obtained. 294 * @syscap SystemCapability.MiscServices.Download 295 * @since 3 296 * @deprecated since 9 297 */ 298 fail?: (data: any, code: number) => void; 299 300 /** 301 * Called when the execution is completed. 302 * @syscap SystemCapability.MiscServices.Download 303 * @since 3 304 * @deprecated since 9 305 */ 306 complete?: () => void; 307} 308 309/** 310 * @deprecated since 9 311 */ 312export default class Request { 313 /** 314 * Upload files. 315 * @param options Options. 316 * @syscap SystemCapability.MiscServices.Upload 317 * @since 3 318 * @deprecated since 9 319 */ 320 static upload(options: UploadRequestOptions): void; 321 322 /** 323 * This API is used to download files. 324 * @param options Options. 325 * @syscap SystemCapability.MiscServices.Download 326 * @since 3 327 * @deprecated since 9 328 */ 329 static download(options: DownloadRequestOptions): void; 330 331 /** 332 * Listens to download task status. 333 * @param options Options. 334 * @syscap SystemCapability.MiscServices.Download 335 * @since 3 336 * @deprecated since 9 337 */ 338 static onDownloadComplete(options: OnDownloadCompleteOptions): void; 339}