• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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 */
15import { AsyncCallback } from './basic';
16import { Callback } from './basic';
17import BaseContext from './application/BaseContext';
18
19/**
20 * upload and download
21 * @permission ohos.permission.INTERNET
22 */
23declare namespace request {
24  /**
25   * Error code 201. the permissions check fails
26   * @syscap SystemCapability.MiscServices.Download
27   * @since 9
28   */
29  const EXCEPTION_PERMISSION: number;
30  /**
31   * Error code 401. the parameters check fails
32   * @syscap SystemCapability.MiscServices.Download
33   * @since 9
34   */
35  const EXCEPTION_PARAMCHECK: number;
36  /**
37   * Error code 801. call unsupported api
38   * @syscap SystemCapability.MiscServices.Download
39   * @since 9
40   */
41  const EXCEPTION_UNSUPPORTED: number;
42  /**
43   * Error code 13400001. file operation error
44   * @syscap SystemCapability.MiscServices.Download
45   * @since 9
46   */
47  const EXCEPTION_FILEIO: number;
48  /**
49   * Error code 13400002. bad file path
50   * @syscap SystemCapability.MiscServices.Download
51   * @since 9
52   */
53  const EXCEPTION_FILEPATH: number;
54  /**
55   * Error code 13400003. task manager service error
56   * @syscap SystemCapability.MiscServices.Download
57   * @since 9
58   */
59  const EXCEPTION_SERVICE: number;
60  /**
61   * Error code 13499999. others error
62   * @syscap SystemCapability.MiscServices.Download
63   * @since 9
64   */
65  const EXCEPTION_OTHERS: number;
66
67  /**
68   * Code 0x00000001. Bit flag indicating download is allowed when using the cellular network.
69   * @syscap SystemCapability.MiscServices.Download
70   * @since 6
71   * @permission ohos.permission.INTERNET
72   */
73  const NETWORK_MOBILE: number;
74
75  /**
76  * Code 0x00010000. Bit flag indicating download is allowed when using the WLAN.
77  * @syscap SystemCapability.MiscServices.Download
78  * @since 6
79  * @permission ohos.permission.INTERNET
80  */
81  const NETWORK_WIFI: number;
82
83  /**
84   * Error code 0. Indicates that the download cannot be resumed for network reasons.
85   * @syscap SystemCapability.MiscServices.Download
86   * @since 7
87   * @permission ohos.permission.INTERNET
88   */
89  const ERROR_CANNOT_RESUME: number;
90
91  /**
92   * Error code 1. Indicates that no storage device, such as an SD card, is found.
93   * @syscap SystemCapability.MiscServices.Download
94   * @since 7
95   * @permission ohos.permission.INTERNET
96   */
97  const ERROR_DEVICE_NOT_FOUND: number;
98
99  /**
100   * Error code 2. Indicates that files to be downloaded already exist, and that the download session cannot overwrite the existing files.
101   * @syscap SystemCapability.MiscServices.Download
102   * @since 7
103   * @permission ohos.permission.INTERNET
104   */
105  const ERROR_FILE_ALREADY_EXISTS: number;
106
107  /**
108   * Error code 3. Indicates that a file operation fails.
109   * @syscap SystemCapability.MiscServices.Download
110   * @since 7
111   * @permission ohos.permission.INTERNET
112   */
113  const ERROR_FILE_ERROR: number;
114
115  /**
116   * Error code 4. Indicates that the HTTP transmission fails.
117   * @syscap SystemCapability.MiscServices.Download
118   * @since 7
119   * @permission ohos.permission.INTERNET
120   */
121  const ERROR_HTTP_DATA_ERROR: number;
122
123  /**
124   * Error code 5. Indicates insufficient storage space.
125   * @syscap SystemCapability.MiscServices.Download
126   * @since 7
127   * @permission ohos.permission.INTERNET
128   */
129  const ERROR_INSUFFICIENT_SPACE: number;
130
131  /**
132   * Error code 6. Indicates an error caused by too many network redirections.
133   * @syscap SystemCapability.MiscServices.Download
134   * @since 7
135   * @permission ohos.permission.INTERNET
136   */
137  const ERROR_TOO_MANY_REDIRECTS: number;
138
139  /**
140   * Error code 7. Indicates an HTTP code that cannot be identified.
141   * @syscap SystemCapability.MiscServices.Download
142   * @since 7
143   * @permission ohos.permission.INTERNET
144   */
145  const ERROR_UNHANDLED_HTTP_CODE: number;
146
147  /**
148   * Error code 8. Indicates an undefined error.
149   * @syscap SystemCapability.MiscServices.Download
150   * @since 7
151   * @permission ohos.permission.INTERNET
152   */
153  const ERROR_UNKNOWN: number;
154
155  /**
156   * Error code 9. Indicates network offline.
157   * @syscap SystemCapability.MiscServices.Download
158   * @since 9
159   * @permission ohos.permission.INTERNET
160   */
161  const ERROR_OFFLINE: number;
162
163  /**
164   * Error code 10. Indicates network type configuration error.
165   * @syscap SystemCapability.MiscServices.Download
166   * @since 9
167   * @permission ohos.permission.INTERNET
168   */
169  const ERROR_UNSUPPORTED_NETWORK_TYPE: number;
170
171  /**
172   * Paused code 0. 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.
173   * @syscap SystemCapability.MiscServices.Download
174   * @since 7
175   * @permission ohos.permission.INTERNET
176   */
177  const PAUSED_QUEUED_FOR_WIFI: number;
178
179  /**
180   * Paused code 1. Indicates that the download is paused due to a network problem, for example, network disconnection.
181   * @syscap SystemCapability.MiscServices.Download
182   * @since 7
183   * @permission ohos.permission.INTERNET
184   */
185  const PAUSED_WAITING_FOR_NETWORK: number;
186
187  /**
188   * Paused code 2. Indicates that a network error occurs, and the download session will be retried.
189   * @syscap SystemCapability.MiscServices.Download
190   * @since 7
191   * @permission ohos.permission.INTERNET
192   */
193  const PAUSED_WAITING_TO_RETRY: number;
194
195  /**
196   * Paused code 3. Indicates that the download is paused due to the user.
197   * @syscap SystemCapability.MiscServices.Download
198   * @since 9
199   * @permission ohos.permission.INTERNET
200   */
201  const PAUSED_BY_USER: number;
202
203  /**
204   * Paused code 4. Indicates that the download is paused for some reasons.
205   * @syscap SystemCapability.MiscServices.Download
206   * @since 7
207   * @permission ohos.permission.INTERNET
208   */
209  const PAUSED_UNKNOWN: number;
210
211  /**
212   * Session status code 0. Indicates that the download session is completed.
213   * @syscap SystemCapability.MiscServices.Download
214   * @since 7
215   * @permission ohos.permission.INTERNET
216   */
217  const SESSION_SUCCESSFUL: number;
218
219  /**
220   * Session status code 1. Indicates that the download session is in progress.
221   * @syscap SystemCapability.MiscServices.Download
222   * @since 7
223   * @permission ohos.permission.INTERNET
224   */
225  const SESSION_RUNNING: number;
226
227  /**
228   * Session status code 2. Indicates that the download session is being scheduled.
229   * @syscap SystemCapability.MiscServices.Download
230   * @since 7
231   * @permission ohos.permission.INTERNET
232   */
233  const SESSION_PENDING: number;
234
235  /**
236   * Session status code 3. Indicates that the download session has been paused.
237   * @syscap SystemCapability.MiscServices.Download
238   * @since 7
239   * @permission ohos.permission.INTERNET
240   */
241  const SESSION_PAUSED: number;
242
243  /**
244   * Session status code 4. Indicates that the download session has failed and will not be retried.
245   * @syscap SystemCapability.MiscServices.Download
246   * @since 7
247   * @permission ohos.permission.INTERNET
248   */
249  const SESSION_FAILED: number;
250
251  /**
252   * Starts a download task.
253   * @syscap SystemCapability.MiscServices.Download
254   * @since 6
255   * @deprecated since 9
256   * @useinstead ohos.request.downloadFile
257   * @param config Download config
258   * @param callback Indicate the callback function to receive DownloadTask.
259   * @permission ohos.permission.INTERNET
260   * @FAModelOnly
261   */
262  function download(config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void;
263
264  /**
265   * Starts a download task.
266   * @syscap SystemCapability.MiscServices.Download
267   * @since 9
268   * @param BaseContext Indicates the application BaseContext.
269   * @param config Download config
270   * @param callback Indicate the callback function to receive DownloadTask.
271   * @permission ohos.permission.INTERNET
272   * @throws {BusinessError} 201 - the permissions check fails
273   * @throws {BusinessError} 401 - the parameters check fails
274   * @throws {BusinessError} 13400001 - file operation error
275   * @throws {BusinessError} 13400002 - bad file path
276   * @throws {BusinessError} 13400003 - task service ability error
277   */
278  function downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void;
279
280  /**
281   * Starts a download task.
282   * @syscap SystemCapability.MiscServices.Download
283   * @since 6
284   * @deprecated since 9,
285   * @useinstead ohos.request.downloadFile
286   * @param config Download config
287   * @permission ohos.permission.INTERNET
288   * @returns { Promise<DownloadTask> } the promise returned by the function.
289   * @FAModelOnly
290   */
291  function download(config: DownloadConfig): Promise<DownloadTask>;
292
293  /**
294   * Starts a download task.
295   * @syscap SystemCapability.MiscServices.Download
296   * @since 9
297   * @param BaseContext Indicates the application BaseContext.
298   * @param config Download config
299   * @permission ohos.permission.INTERNET
300   * @returns { Promise<DownloadTask> } the promise returned by the function.
301   * @throws {BusinessError} 201 - the permissions check fails
302   * @throws {BusinessError} 401 - the parameters check fails
303   * @throws {BusinessError} 13400001 - file operation error
304   * @throws {BusinessError} 13400002 - bad file path
305   * @throws {BusinessError} 13400003 - task service ability error
306   */
307  function downloadFile(context: BaseContext, config: DownloadConfig): Promise<DownloadTask>;
308
309  /**
310   * Starts a upload task.
311   * @syscap SystemCapability.MiscServices.Upload
312   * @since 6
313   * @deprecated since 9
314   * @useinstead ohos.request.uploadFile
315   * @param config Upload config
316   * @param callback Indicate the callback function to receive UploadTask.
317   * @permission ohos.permission.INTERNET
318   * @FAModelOnly
319   */
320  function upload(config: UploadConfig, callback: AsyncCallback<UploadTask>): void;
321
322  /**
323   * Starts a upload task.
324   * @syscap SystemCapability.MiscServices.Upload
325   * @since 9
326   * @param BaseContext Indicates the application BaseContext.
327   * @param config Upload config
328   * @param callback Indicate the callback function to receive UploadTask.
329   * @permission ohos.permission.INTERNET
330   * @throws {BusinessError} 201 - the permissions check fails
331   * @throws {BusinessError} 401 - the parameters check fails
332   * @throws {BusinessError} 13400002 - bad file path
333   */
334  function uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback<UploadTask>): void;
335
336  /**
337   * Starts a upload task.
338   * @syscap SystemCapability.MiscServices.Upload
339   * @since 6
340   * @deprecated since 9
341   * @useinstead ohos.request.uploadFile
342   * @param config Upload config
343   * @permission ohos.permission.INTERNET
344   * @returns { Promise<UploadTask> } the promise returned by the function.
345   * @FAModelOnly
346   */
347  function upload(config: UploadConfig): Promise<UploadTask>;
348
349  /**
350   * Starts a upload task.
351   * @syscap SystemCapability.MiscServices.Upload
352   * @since 9
353   * @param BaseContext Indicates the application BaseContext.
354   * @param config Upload config
355   * @permission ohos.permission.INTERNET
356   * @returns { Promise<UploadTask> } the promise returned by the function.
357   * @throws {BusinessError} 201 - the permissions check fails
358   * @throws {BusinessError} 401 - the parameters check fails
359   * @throws {BusinessError} 13400002 - bad file path
360   */
361  function uploadFile(context: BaseContext, config: UploadConfig): Promise<UploadTask>;
362
363  /**
364   * DownloadConfig data Structure
365   *
366   * @name DownloadConfig
367   * @since 6
368   * @syscap SystemCapability.MiscServices.Download
369   * @permission ohos.permission.INTERNET
370   */
371  interface DownloadConfig {
372    /**
373     * Resource address.
374     *
375     * @since 6
376     * @permission ohos.permission.INTERNET
377     */
378    url: string;
379    /**
380     * Adds an HTTP or HTTPS header to be included with the download request.
381     *
382     * @since 6
383     * @permission ohos.permission.INTERNET
384     */
385    header?: Object;
386    /**
387     * Allows download under a metered connection.
388     *
389     * @since 6
390     * @permission ohos.permission.INTERNET
391     */
392    enableMetered?: boolean;
393    /**
394     * Allows download in a roaming network.
395     *
396     * @since 6
397     * @permission ohos.permission.INTERNET
398     */
399    enableRoaming?: boolean;
400    /**
401     * Sets the description of a download session.
402     *
403     * @since 6
404     * @permission ohos.permission.INTERNET
405     */
406    description?: string;
407    /**
408     * Sets the network type allowed for download.
409     *
410     * @since 6
411     * @permission ohos.permission.INTERNET
412     */
413    networkType?: number;
414    /**
415     * Sets the path for downloads.
416     *
417     * @since 7
418     * @permission ohos.permission.INTERNET
419     */
420    filePath?: string;
421    /**
422     * Sets a download session title.
423     *
424     * @since 6
425     * @permission ohos.permission.INTERNET
426     */
427    title?: string;
428    /**
429     * Allow download background task notifications.
430     *
431     * @since 9
432     */
433    background?: boolean;
434  }
435
436  /**
437   * DownloadInfo data Structure
438   *
439   * @name DownloadInfo
440   * @syscap SystemCapability.MiscServices.Download
441   * @since 7
442   * @permission ohos.permission.INTERNET
443   */
444  interface DownloadInfo {
445    /**
446     * the description of a file to be downloaded.
447     *
448     * @since 7
449     * @permission ohos.permission.INTERNET
450     */
451    description: string;
452    /**
453     * the real-time downloads size (in bytes).
454     *
455     * @since 7
456     * @permission ohos.permission.INTERNET
457     */
458    downloadedBytes: number;
459    /**
460     * the ID of a file to be downloaded.
461     *
462     * @since 7
463     * @permission ohos.permission.INTERNET
464     */
465    downloadId: number;
466    /**
467     * a download failure cause, which can be any DownloadSession.ERROR_* constant.
468     *
469     * @since 7
470     * @permission ohos.permission.INTERNET
471     */
472    failedReason: number;
473    /**
474     * the name of a file to be downloaded.
475     *
476     * @since 7
477     * @permission ohos.permission.INTERNET
478     */
479    fileName: string;
480    /**
481     * the URI of a stored file.
482     *
483     * @since 7
484     * @permission ohos.permission.INTERNET
485     */
486    filePath: string;
487    /**
488     * the reason why a session is paused, which can be any DownloadSession.PAUSED_* constant.
489     *
490     * @since 7
491     * @permission ohos.permission.INTERNET
492     */
493    pausedReason: number;
494    /**
495     * the download status code, which can be any DownloadSession.SESSION_* constant.
496     *
497     * @since 7
498     * @permission ohos.permission.INTERNET
499     */
500    status: number;
501    /**
502     * the URI of files to be downloaded.
503     *
504     * @since 7
505     * @permission ohos.permission.INTERNET
506     */
507    targetURI: string;
508    /**
509     * the title of a file to be downloaded.
510     *
511     * @since 7
512     * @permission ohos.permission.INTERNET
513     */
514    downloadTitle: string;
515    /**
516     * the total size of files to be downloaded (in bytes).
517     *
518     * @since 7
519     * @permission ohos.permission.INTERNET
520     */
521    downloadTotalBytes: number;
522  }
523
524  /**
525   * Download task interface
526   * @permission ohos.permission.INTERNET
527   * @since 6
528   * @syscap SystemCapability.MiscServices.Download
529   */
530  interface DownloadTask {
531    /**
532     * Called when the current download session is in process.
533     * @syscap SystemCapability.MiscServices.Download
534     * @since 6
535     * @param type progress Indicates the download task progress.
536     * @param callback The callback function for the download progress change event
537     *        receivedSize the length of downloaded data, in bytes
538     *        totalSize he length of data expected to be downloaded, in bytes.
539     * @permission ohos.permission.INTERNET
540     */
541    on(type: 'progress', callback: (receivedSize: number, totalSize: number) => void): void;
542
543    /**
544     * Called when the current download session is in process.
545     * @syscap SystemCapability.MiscServices.Download
546     * @since 6
547     * @param type progress Indicates the download task progress.
548     * @param callback The callback function for the download progress change event
549     *        receivedSize the length of downloaded data, in bytes
550     *        totalSize he length of data expected to be downloaded, in bytes.
551     * @permission ohos.permission.INTERNET
552     */
553    off(type: 'progress', callback?: (receivedSize: number, totalSize: number) => void): void;
554
555    /**
556     * Called when the current download session complete pause or remove.
557     * @syscap SystemCapability.MiscServices.Download
558     * @since 7
559     * @param type Indicates the download session event type
560     *        complete: download task completed,
561     *        pause: download task stopped,
562     *        remove: download task deleted.
563     * @param callback The callback function for the download complete pause or remove change event.
564     * @permission ohos.permission.INTERNET
565     */
566    on(type: 'complete' | 'pause' | 'remove', callback: () => void): void;
567
568    /**
569     * Called when the current download session complete pause or remove.
570     * @syscap SystemCapability.MiscServices.Download
571     * @since 7
572     * @param type Indicates the download session event type
573     *        complete: download task completed,
574     *        pause: download task stopped,
575     *        remove: download task deleted.
576     * @param callback The callback function for the download complete pause or remove change event.
577     * @permission ohos.permission.INTERNET
578     */
579    off(type: 'complete' | 'pause' | 'remove', callback?: () => void): void;
580
581    /**
582     * Called when the current download session fails.
583     * @syscap SystemCapability.MiscServices.Download
584     * @since 7
585     * @param type Indicates the download session type, fail: download task has failed.
586     * @param callback The callback function for the download fail change event
587     *        err The error code for download task.
588     * @permission ohos.permission.INTERNET
589     */
590    on(type: 'fail', callback: (err: number) => void): void;
591
592    /**
593     * Called when the current download session fails.
594     * @syscap SystemCapability.MiscServices.Download
595     * @since 7
596     * @param type Indicates the download session type, fail: download task has failed.
597     * @param callback Indicate the callback function to receive err.
598     *        err The error code for download task.
599     * @permission ohos.permission.INTERNET
600     */
601    off(type: 'fail', callback?: (err: number) => void): void;
602
603    /**
604     * Deletes a download session and the downloaded files.
605     * @syscap SystemCapability.MiscServices.Download
606     * @since 6
607     * @deprecated since 9
608     * @useinstead ohos.request.delete
609     * @param callback Indicates asynchronous invoking Result.
610     * @permission ohos.permission.INTERNET
611     */
612    remove(callback: AsyncCallback<boolean>): void;
613
614    /**
615     * Deletes a download session and the downloaded files.
616     * @syscap SystemCapability.MiscServices.Download
617     * @since 6
618     * @deprecated since 9
619     * @useinstead ohos.request.delete
620     * @permission ohos.permission.INTERNET
621     * @returns { Promise<boolean> } the promise returned by the function.
622     */
623    remove(): Promise<boolean>;
624
625    /**
626     * Pause a download session.
627     * @syscap SystemCapability.MiscServices.Download
628     * @since 7
629     * @deprecated since 9
630     * @useinstead ohos.request.suspend
631     * @param callback Indicates asynchronous invoking Result.
632     * @permission ohos.permission.INTERNET
633     */
634    pause(callback: AsyncCallback<void>): void;
635
636    /**
637     * Pause a download session.
638     * @syscap SystemCapability.MiscServices.Download
639     * @since 7
640     * @deprecated since 9
641     * @useinstead ohos.request.suspend
642     * @permission ohos.permission.INTERNET
643     * @returns { Promise<void> } the promise returned by the function.
644     */
645    pause(): Promise<void>;
646
647    /**
648     * Resume a paused download session.
649     * @syscap SystemCapability.MiscServices.Download
650     * @since 7
651     * @deprecated since 9
652     * @useinstead ohos.request.restore
653     * @param callback Indicates asynchronous invoking Result.
654     * @permission ohos.permission.INTERNET
655     */
656    resume(callback: AsyncCallback<void>): void;
657
658    /**
659     * Resume a paused download session.
660     * @syscap SystemCapability.MiscServices.Download
661     * @since 7
662     * @deprecated since 9
663     * @useinstead ohos.request.restore
664     * @permission ohos.permission.INTERNET
665     * @returns { Promise<void> } the promise returned by the function.
666     */
667    resume(): Promise<void>;
668
669    /**
670     * Queries download information of a session, which is defined in DownloadSession.DownloadInfo.
671     * @syscap SystemCapability.MiscServices.Download
672     * @since 7
673     * @deprecated since 9
674     * @useinstead ohos.request.getTaskInfo
675     * @param callback Indicate the callback function to receive download info.
676     * @permission ohos.permission.INTERNET
677     */
678    query(callback: AsyncCallback<DownloadInfo>): void;
679
680    /**
681     * Queries download information of a session, which is defined in DownloadSession.DownloadInfo.
682     * @syscap SystemCapability.MiscServices.Download
683     * @since 7
684     * @deprecated since 9
685     * @useinstead ohos.request.getTaskInfo
686     * @permission ohos.permission.INTERNET
687     * @returns { Promise<DownloadInfo> } the promise returned by the function.
688     */
689    query(): Promise<DownloadInfo>;
690
691    /**
692     * Queries the MIME type of the download file.
693     * @syscap SystemCapability.MiscServices.Download
694     * @since 7
695     * @deprecated since 9
696     * @useinstead ohos.request.getTaskMimeType
697     * @param callback Indicate the callback function to receive download file MIME type.
698     * @permission ohos.permission.INTERNET
699     */
700    queryMimeType(callback: AsyncCallback<string>): void;
701
702    /**
703     * Queries the MIME type of the download file.
704     * @syscap SystemCapability.MiscServices.Download
705     * @since 7
706     * @deprecated since 9
707     * @useinstead ohos.request.getTaskMimeType
708     * @permission ohos.permission.INTERNET
709     * @returns { Promise<string> } the promise returned by the function.
710     */
711    queryMimeType(): Promise<string>;
712
713    /**
714     * Delete the download task
715     * @since 9
716     * @permission ohos.permission.INTERNET
717     * @throws {BusinessError} 201 - the permissions check fails
718     * @throws {BusinessError} 401 - the parameters check fails
719     * @syscap SystemCapability.MiscServices.Download
720     */
721    delete(callback: AsyncCallback<boolean>): void;
722
723    /**
724     * Delete the download task
725     * @since 9
726     * @permission ohos.permission.INTERNET
727     * @throws {BusinessError} 201 - the permissions check fails
728     * @throws {BusinessError} 401 - the parameters check fails
729     * @syscap SystemCapability.MiscServices.Download
730     * @returns { Promise<boolean> } the promise returned by the function.
731     */
732    delete(): Promise<boolean>;
733
734    /**
735     * Suspend the download task
736     * @since 9
737     * @permission ohos.permission.INTERNET
738     * @throws {BusinessError} 201 - the permissions check fails
739     * @throws {BusinessError} 401 - the parameters check fails
740     * @syscap SystemCapability.MiscServices.Download
741     */
742    suspend(callback: AsyncCallback<boolean>): void;
743
744    /**
745     * Suspend the download task
746     * @since 9
747     * @permission ohos.permission.INTERNET
748     * @throws {BusinessError} 201 - the permissions check fails
749     * @throws {BusinessError} 401 - the parameters check fails
750     * @syscap SystemCapability.MiscServices.Download
751     * @returns { Promise<boolean> } the promise returned by the function.
752     */
753    suspend(): Promise<boolean>;
754
755    /**
756     * Restore the download task
757     * @since 9
758     * @permission ohos.permission.INTERNET
759     * @throws {BusinessError} 201 - the permissions check fails
760     * @throws {BusinessError} 401 - the parameters check fails
761     * @syscap SystemCapability.MiscServices.Download
762     */
763    restore(callback: AsyncCallback<boolean>): void;
764
765    /**
766     * Restore the download task
767     * @since 9
768     * @permission ohos.permission.INTERNET
769     * @throws {BusinessError} 201 - the permissions check fails
770     * @throws {BusinessError} 401 - the parameters check fails
771     * @syscap SystemCapability.MiscServices.Download
772     * @returns { Promise<boolean> } the promise returned by the function.
773     */
774    restore(): Promise<boolean>;
775
776    /**
777     * Get the download task info
778     * @since 9
779     * @permission ohos.permission.INTERNET
780     * @throws {BusinessError} 201 - the permissions check fails
781     * @throws {BusinessError} 401 - the parameters check fails
782     * @syscap SystemCapability.MiscServices.Download
783     */
784    getTaskInfo(callback: AsyncCallback<DownloadInfo>): void;
785
786    /**
787     * Get the download task info
788     * @since 9
789     * @permission ohos.permission.INTERNET
790     * @throws {BusinessError} 201 - the permissions check fails
791     * @throws {BusinessError} 401 - the parameters check fails
792     * @syscap SystemCapability.MiscServices.Download
793     * @returns { Promise<DownloadInfo> } the promise returned by the function.
794     */
795    getTaskInfo(): Promise<DownloadInfo>;
796
797    /**
798     * Get mimetype of the download task
799     * @since 9
800     * @permission ohos.permission.INTERNET
801     * @throws {BusinessError} 201 - the permissions check fails
802     * @throws {BusinessError} 401 - the parameters check fails
803     * @syscap SystemCapability.MiscServices.Download
804     */
805    getTaskMimeType(callback: AsyncCallback<string>): void;
806
807    /**
808     * Get mimetype of the download task
809     * @since 9
810     * @permission ohos.permission.INTERNET
811     * @throws {BusinessError} 201 - the permissions check fails
812     * @throws {BusinessError} 401 - the parameters check fails
813     * @syscap SystemCapability.MiscServices.Download
814     * @returns { Promise<string> } the promise returned by the function.
815     */
816    getTaskMimeType(): Promise<string>;
817  }
818
819  /**
820   * File data Structure
821   *
822   * @name File
823   * @since 6
824   * @syscap SystemCapability.MiscServices.Download
825   * @permission ohos.permission.INTERNET
826   */
827  interface File {
828    /**
829     * When multipart is submitted, the file name in the request header.
830     *
831     * @since 6
832     * @permission ohos.permission.INTERNET
833     */
834    filename: string;
835    /**
836     * When multipart is submitted, the name of the form item. The default is file.
837     *
838     * @since 6
839     * @permission ohos.permission.INTERNET
840     */
841    name: string;
842    /**
843     * The local storage path of the file (please refer to the storage directory definition for path usage).
844     *
845     * @since 6
846     * @permission ohos.permission.INTERNET
847     */
848    uri: string;
849    /**
850     * The content type of the file is obtained by default according to the suffix of the file name or path.
851     *
852     * @since 6
853     * @permission ohos.permission.INTERNET
854     */
855    type: string;
856  }
857
858  /**
859   * RequestData data Structure
860   *
861   * @name RequestData
862   * @since 6
863   * @syscap SystemCapability.MiscServices.Download
864   * @permission ohos.permission.INTERNET
865   */
866  interface RequestData {
867    /**
868     * Represents the name of the form element.
869     *
870     * @since 6
871     * @permission ohos.permission.INTERNET
872     */
873    name: string;
874    /**
875     * Represents the value of the form element.
876     *
877     * @since 6
878     * @permission ohos.permission.INTERNET
879     */
880    value: string;
881  }
882
883  /**
884   * UploadConfig data Structure
885   *
886   * @name UploadConfig
887   * @since 6
888   * @syscap SystemCapability.MiscServices.Upload
889   * @permission ohos.permission.INTERNET
890   */
891  interface UploadConfig {
892    /**
893     * Resource address.
894     *
895     * @since 6
896     * @permission ohos.permission.INTERNET
897     */
898    url: string;
899    /**
900     * Adds an HTTP or HTTPS header to be included with the upload request.
901     *
902     * @since 6
903     * @permission ohos.permission.INTERNET
904     */
905    header: Object;
906    /**
907     * Request method: POST, PUT. The default POST.
908     *
909     * @since 6
910     * @permission ohos.permission.INTERNET
911     */
912    method: string;
913    /**
914     * A list of files to be uploaded. Please use multipart/form-data to submit.
915     *
916     * @since 6
917     * @permission ohos.permission.INTERNET
918     */
919    files: Array<File>;
920    /**
921     * The requested form data.
922     *
923     * @since 6
924     * @permission ohos.permission.INTERNET
925     */
926    data: Array<RequestData>;
927  }
928
929  /**
930   * TaskState data Structure
931   *
932   * @name TaskState
933   * @since 9
934   * @syscap SystemCapability.MiscServices.Upload
935   * @permission ohos.permission.INTERNET
936   */
937   interface TaskState {
938    /**
939     * Upload file path.
940     *
941     * @since 9
942     * @permission ohos.permission.INTERNET
943     */
944    path: string;
945    /**
946     * Upload task return value.
947     *
948     * @since 9
949     * @permission ohos.permission.INTERNET
950     */
951    responseCode: number;
952    /**
953     * Upload task information.
954     *
955     * @since 9
956     * @permission ohos.permission.INTERNET
957     */
958    message: string;
959  }
960
961  /**
962   * Upload task interface
963   * @permission ohos.permission.INTERNET
964   * @since 6
965   * @syscap SystemCapability.MiscServices.Download
966   */
967  interface UploadTask {
968    /**
969     * Called when the current upload session is in process.
970     * @syscap SystemCapability.MiscServices.Upload
971     * @since 6
972     * @param type progress Indicates the upload task progress.
973     * @param callback The callback function for the upload progress change event
974     *        uploadedSize The length of uploaded data, in bytes
975     *        totalSize The length of data expected to be uploaded, in bytes.
976     * @permission ohos.permission.INTERNET
977     */
978    on(type: 'progress', callback: (uploadedSize: number, totalSize: number) => void): void;
979
980    /**
981     * Called when the current upload session is in process.
982     * @syscap SystemCapability.MiscServices.Upload
983     * @since 6
984     * @param type progress Indicates the upload task progress.
985     * @param callback The callback function for the upload progress change event
986     *        uploadedSize The length of uploaded data, in bytes
987     *        totalSize The length of data expected to be uploaded, in bytes.
988     * @permission ohos.permission.INTERNET
989     */
990    off(type: 'progress', callback?: (uploadedSize: number, totalSize: number) => void): void;
991
992    /**
993     * Called when the header of the current upload session has been received.
994     * @syscap SystemCapability.MiscServices.Upload
995     * @since 7
996     * @param type headerReceive Indicates the upload task headed receive.
997     * @param callback The callback function for the HTTP Response Header event
998     *        header HTTP Response Header returned by the developer server.
999     * @permission ohos.permission.INTERNET
1000     */
1001    on(type: 'headerReceive', callback: (header: object) => void): void;
1002
1003    /**
1004     * Called when the header of the current upload session has been received.
1005     * @syscap SystemCapability.MiscServices.Upload
1006     * @since 7
1007     * @param type headerReceive Indicates the upload task headed receive.
1008     * @param callback The callback function for the HTTP Response Header event
1009     *        header HTTP Response Header returned by the developer server.
1010     * @permission ohos.permission.INTERNET
1011     */
1012    off(type: 'headerReceive', callback?: (header: object) => void): void;
1013
1014    /**
1015     * Called when the current upload session complete or fail.
1016     * @syscap SystemCapability.MiscServices.Upload
1017     * @since 9
1018     * @param type Indicates the upload session event type
1019     *        complete: upload task completed
1020     *        fail: upload task failed
1021     * @param callback The callback function for the upload complete or fail change event.
1022     * @permission ohos.permission.INTERNET
1023     */
1024     on(type:'complete' | 'fail', callback: Callback<Array<TaskState>>): void;
1025
1026     /**
1027      * Called when the current upload session complete or fail.
1028      * @syscap SystemCapability.MiscServices.Upload
1029      * @since 9
1030      * @param type Indicates the upload session event type
1031      *        complete: upload task completed
1032     *         fail: upload task failed
1033      * @permission ohos.permission.INTERNET
1034      */
1035    off(type:'complete' | 'fail', callback?: Callback<Array<TaskState>>): void;
1036
1037    /**
1038     * Deletes a upload session.
1039     * @syscap SystemCapability.MiscServices.Upload
1040     * @since 6
1041     * @deprecated since 9
1042     * @useinstead ohos.request.delete
1043     * @param callback Indicates asynchronous invoking Result.
1044     * @permission ohos.permission.INTERNET
1045     */
1046    remove(callback: AsyncCallback<boolean>): void;
1047
1048    /**
1049     * Deletes a upload session.
1050     * @syscap SystemCapability.MiscServices.Upload
1051     * @since 6
1052     * @deprecated since 9
1053     * @useinstead ohos.request.delete
1054     * @permission ohos.permission.INTERNET
1055     * @returns { Promise<boolean> } the promise returned by the function.
1056     */
1057    remove(): Promise<boolean>;
1058
1059    /**
1060     * Delete the upload task
1061     * @since 9
1062     * @permission ohos.permission.INTERNET
1063     * @throws {BusinessError} 201 - the permissions check fails
1064     * @throws {BusinessError} 401 - the parameters check fails
1065     * @syscap SystemCapability.MiscServices.Upload
1066     */
1067    delete(callback: AsyncCallback<boolean>): void;
1068
1069    /**
1070     * Delete the upload task
1071     * @since 9
1072     * @permission ohos.permission.INTERNET
1073     * @throws {BusinessError} 201 - the permissions check fails
1074     * @throws {BusinessError} 401 - the parameters check fails
1075     * @syscap SystemCapability.MiscServices.Upload
1076     * @returns { Promise<boolean> } the promise returned by the function.
1077     */
1078    delete(): Promise<boolean>;
1079  }
1080}
1081
1082export default request;
1083
1084