• 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 */
15
16import { AsyncCallback } from './@ohos.base';
17import { Callback } from './@ohos.base';
18import BaseContext from './application/BaseContext';
19
20/**
21 * upload and download
22 *
23 * @namespace request
24 * @permission ohos.permission.INTERNET
25 * @since 6
26 */
27/**
28 * upload and download
29 *
30 * @namespace request
31 * @since 10
32 */
33declare namespace request {
34  /**
35   * Error code 201 - the permissions check fails.
36   *
37   * @permission ohos.permission.INTERNET
38   * @constant
39   * @syscap SystemCapability.MiscServices.Download
40   * @since 9
41   */
42  /**
43   * Error code 201 - the permissions check fails.
44   *
45   * @permission ohos.permission.INTERNET
46   * @constant
47   * @syscap SystemCapability.MiscServices.Download
48   * @crossplatform
49   * @since 10
50   */
51  const EXCEPTION_PERMISSION: number;
52  /**
53   * Error code 401 - the parameters check fails.
54   *
55   * @permission ohos.permission.INTERNET
56   * @constant
57   * @syscap SystemCapability.MiscServices.Download
58   * @since 9
59   */
60  /**
61   * Error code 401 - the parameters check fails.
62   *
63   * @permission ohos.permission.INTERNET
64   * @constant
65   * @syscap SystemCapability.MiscServices.Download
66   * @crossplatform
67   * @since 10
68   */
69  const EXCEPTION_PARAMCHECK: number;
70  /**
71   * Error code 801 - call unsupported api.
72   *
73   * @permission ohos.permission.INTERNET
74   * @constant
75   * @syscap SystemCapability.MiscServices.Download
76   * @since 9
77   */
78  /**
79   * Error code 801 - call unsupported api.
80   *
81   * @permission ohos.permission.INTERNET
82   * @constant
83   * @syscap SystemCapability.MiscServices.Download
84   * @crossplatform
85   * @since 10
86   */
87  const EXCEPTION_UNSUPPORTED: number;
88  /**
89   * Error code 13400001 - file operation error.
90   *
91   * @permission ohos.permission.INTERNET
92   * @constant
93   * @syscap SystemCapability.MiscServices.Download
94   * @since 9
95   */
96  /**
97   * Error code 13400001 - file operation error.
98   *
99   * @permission ohos.permission.INTERNET
100   * @constant
101   * @syscap SystemCapability.MiscServices.Download
102   * @crossplatform
103   * @since 10
104   */
105  const EXCEPTION_FILEIO: number;
106  /**
107   * Error code 13400002 - bad file path.
108   *
109   * @permission ohos.permission.INTERNET
110   * @constant
111   * @syscap SystemCapability.MiscServices.Download
112   * @since 9
113   */
114  /**
115   * Error code 13400002 - bad file path.
116   *
117   * @permission ohos.permission.INTERNET
118   * @constant
119   * @syscap SystemCapability.MiscServices.Download
120   * @crossplatform
121   * @since 10
122   */
123  const EXCEPTION_FILEPATH: number;
124  /**
125   * Error code 13400003 - task manager service error.
126   *
127   * @permission ohos.permission.INTERNET
128   * @constant
129   * @syscap SystemCapability.MiscServices.Download
130   * @since 9
131   */
132  /**
133   * Error code 13400003 - task manager service error.
134   *
135   * @permission ohos.permission.INTERNET
136   * @constant
137   * @syscap SystemCapability.MiscServices.Download
138   * @crossplatform
139   * @since 10
140   */
141  const EXCEPTION_SERVICE: number;
142  /**
143   * Error code 13499999 - others error.
144   *
145   * @permission ohos.permission.INTERNET
146   * @constant
147   * @syscap SystemCapability.MiscServices.Download
148   * @since 9
149   */
150  /**
151   * Error code 13499999 - others error.
152   *
153   * @permission ohos.permission.INTERNET
154   * @constant
155   * @syscap SystemCapability.MiscServices.Download
156   * @crossplatform
157   * @since 10
158   */
159  const EXCEPTION_OTHERS: number;
160
161  /**
162   * Code 0x00000001 - Bit flag indicating download is allowed when using the cellular network.
163   *
164   * @permission ohos.permission.INTERNET
165   * @constant
166   * @syscap SystemCapability.MiscServices.Download
167   * @since 6
168   */
169  /**
170   * Code 0x00000001 - Bit flag indicating download is allowed when using the cellular network.
171   *
172   * @permission ohos.permission.INTERNET
173   * @constant
174   * @syscap SystemCapability.MiscServices.Download
175   * @crossplatform
176   * @since 10
177   */
178  const NETWORK_MOBILE: number;
179
180  /**
181   * Code 0x00010000 - Bit flag indicating download is allowed when using the WLAN.
182   *
183   * @permission ohos.permission.INTERNET
184   * @constant
185   * @syscap SystemCapability.MiscServices.Download
186   * @since 6
187   */
188  /**
189   * Code 0x00010000 - Bit flag indicating download is allowed when using the WLAN.
190   *
191   * @permission ohos.permission.INTERNET
192   * @constant
193   * @syscap SystemCapability.MiscServices.Download
194   * @crossplatform
195   * @since 10
196   */
197  const NETWORK_WIFI: number;
198
199  /**
200   * Error code 0 - Indicates that the download cannot be resumed for network reasons.
201   *
202   * @permission ohos.permission.INTERNET
203   * @constant
204   * @syscap SystemCapability.MiscServices.Download
205   * @since 7
206   */
207  /**
208   * Error code 0 - Indicates that the download cannot be resumed for network reasons.
209   *
210   * @permission ohos.permission.INTERNET
211   * @constant
212   * @syscap SystemCapability.MiscServices.Download
213   * @crossplatform
214   * @since 10
215   */
216  const ERROR_CANNOT_RESUME: number;
217
218  /**
219   * Error code 1 - Indicates that no storage device, such as an SD card, is found.
220   *
221   * @permission ohos.permission.INTERNET
222   * @constant
223   * @syscap SystemCapability.MiscServices.Download
224   * @since 7
225   */
226  /**
227   * Error code 1 - Indicates that no storage device, such as an SD card, is found.
228   *
229   * @permission ohos.permission.INTERNET
230   * @constant
231   * @syscap SystemCapability.MiscServices.Download
232   * @crossplatform
233   * @since 10
234   */
235  const ERROR_DEVICE_NOT_FOUND: number;
236
237  /**
238   * Error code 2 - Indicates that files to be downloaded already exist, and that the download session cannot overwrite the existing files.
239   *
240   * @permission ohos.permission.INTERNET
241   * @constant
242   * @syscap SystemCapability.MiscServices.Download
243   * @since 7
244   */
245  /**
246   * Error code 2 - Indicates that files to be downloaded already exist, and that the download session cannot overwrite the existing files.
247   *
248   * @permission ohos.permission.INTERNET
249   * @constant
250   * @syscap SystemCapability.MiscServices.Download
251   * @crossplatform
252   * @since 10
253   */
254  const ERROR_FILE_ALREADY_EXISTS: number;
255
256  /**
257   * Error code 3 - Indicates that a file operation fails.
258   *
259   * @permission ohos.permission.INTERNET
260   * @constant
261   * @syscap SystemCapability.MiscServices.Download
262   * @since 7
263   */
264  /**
265   * Error code 3 - Indicates that a file operation fails.
266   *
267   * @permission ohos.permission.INTERNET
268   * @constant
269   * @syscap SystemCapability.MiscServices.Download
270   * @crossplatform
271   * @since 10
272   */
273  const ERROR_FILE_ERROR: number;
274
275  /**
276   * Error code 4 - Indicates that the HTTP transmission fails.
277   *
278   * @permission ohos.permission.INTERNET
279   * @constant
280   * @syscap SystemCapability.MiscServices.Download
281   * @since 7
282   */
283  /**
284   * Error code 4 - Indicates that the HTTP transmission fails.
285   *
286   * @permission ohos.permission.INTERNET
287   * @constant
288   * @syscap SystemCapability.MiscServices.Download
289   * @crossplatform
290   * @since 10
291   */
292  const ERROR_HTTP_DATA_ERROR: number;
293
294  /**
295   * Error code 5 - Indicates insufficient storage space.
296   *
297   * @permission ohos.permission.INTERNET
298   * @constant
299   * @syscap SystemCapability.MiscServices.Download
300   * @since 7
301   */
302  /**
303   * Error code 5 - Indicates insufficient storage space.
304   *
305   * @permission ohos.permission.INTERNET
306   * @constant
307   * @syscap SystemCapability.MiscServices.Download
308   * @crossplatform
309   * @since 10
310   */
311  const ERROR_INSUFFICIENT_SPACE: number;
312
313  /**
314   * Error code 6 - Indicates an error caused by too many network redirections.
315   *
316   * @permission ohos.permission.INTERNET
317   * @constant
318   * @syscap SystemCapability.MiscServices.Download
319   * @since 7
320   */
321  /**
322   * Error code 6 - Indicates an error caused by too many network redirections.
323   *
324   * @permission ohos.permission.INTERNET
325   * @constant
326   * @syscap SystemCapability.MiscServices.Download
327   * @crossplatform
328   * @since 10
329   */
330  const ERROR_TOO_MANY_REDIRECTS: number;
331
332  /**
333   * Error code 7 - Indicates an HTTP code that cannot be identified.
334   *
335   * @permission ohos.permission.INTERNET
336   * @constant
337   * @syscap SystemCapability.MiscServices.Download
338   * @since 7
339   */
340  /**
341   * Error code 7 - Indicates an HTTP code that cannot be identified.
342   *
343   * @permission ohos.permission.INTERNET
344   * @constant
345   * @syscap SystemCapability.MiscServices.Download
346   * @crossplatform
347   * @since 10
348   */
349  const ERROR_UNHANDLED_HTTP_CODE: number;
350
351  /**
352   * Error code 8 - Indicates an undefined error.
353   *
354   * @permission ohos.permission.INTERNET
355   * @constant
356   * @syscap SystemCapability.MiscServices.Download
357   * @since 7
358   */
359  /**
360   * Error code 8 - Indicates an undefined error.
361   *
362   * @permission ohos.permission.INTERNET
363   * @constant
364   * @syscap SystemCapability.MiscServices.Download
365   * @crossplatform
366   * @since 10
367   */
368  const ERROR_UNKNOWN: number;
369
370  /**
371   * Error code 9 - Indicates network offline.
372   *
373   * @permission ohos.permission.INTERNET
374   * @constant
375   * @syscap SystemCapability.MiscServices.Download
376   * @since 9
377   */
378  /**
379   * Error code 9 - Indicates network offline.
380   *
381   * @permission ohos.permission.INTERNET
382   * @constant
383   * @syscap SystemCapability.MiscServices.Download
384   * @crossplatform
385   * @since 10
386   */
387  const ERROR_OFFLINE: number;
388
389  /**
390   * Error code 10 - Indicates network type configuration error.
391   *
392   * @permission ohos.permission.INTERNET
393   * @constant
394   * @syscap SystemCapability.MiscServices.Download
395   * @since 9
396   */
397  /**
398   * Error code 10 - Indicates network type configuration error.
399   *
400   * @permission ohos.permission.INTERNET
401   * @constant
402   * @syscap SystemCapability.MiscServices.Download
403   * @crossplatform
404   * @since 10
405   */
406  const ERROR_UNSUPPORTED_NETWORK_TYPE: number;
407
408  /**
409   * Paused code 0 - Indicates that the download is paused and waiting for a WLAN connection,
410   * because the file size exceeds the maximum allowed for a session using the cellular network.
411   *
412   * @permission ohos.permission.INTERNET
413   * @constant
414   * @syscap SystemCapability.MiscServices.Download
415   * @since 7
416   */
417  /**
418   * Paused code 0 - Indicates that the download is paused and waiting for a WLAN connection,
419   * because the file size exceeds the maximum allowed for a session using the cellular network.
420   *
421   * @permission ohos.permission.INTERNET
422   * @constant
423   * @syscap SystemCapability.MiscServices.Download
424   * @crossplatform
425   * @since 10
426   */
427  const PAUSED_QUEUED_FOR_WIFI: number;
428
429  /**
430   * Paused code 1 - Indicates that the download is paused due to a network problem, for example, network disconnection.
431   *
432   * @permission ohos.permission.INTERNET
433   * @constant
434   * @syscap SystemCapability.MiscServices.Download
435   * @since 7
436   */
437  /**
438   * Paused code 1 - Indicates that the download is paused due to a network problem, for example, network disconnection.
439   *
440   * @permission ohos.permission.INTERNET
441   * @constant
442   * @syscap SystemCapability.MiscServices.Download
443   * @crossplatform
444   * @since 10
445   */
446  const PAUSED_WAITING_FOR_NETWORK: number;
447
448  /**
449   * Paused code 2 - Indicates that a network error occurs, and the download session will be retried.
450   *
451   * @permission ohos.permission.INTERNET
452   * @constant
453   * @syscap SystemCapability.MiscServices.Download
454   * @since 7
455   */
456  /**
457   * Paused code 2 - Indicates that a network error occurs, and the download session will be retried.
458   *
459   * @permission ohos.permission.INTERNET
460   * @constant
461   * @syscap SystemCapability.MiscServices.Download
462   * @crossplatform
463   * @since 10
464   */
465  const PAUSED_WAITING_TO_RETRY: number;
466
467  /**
468   * Paused code 3 - Indicates that the download is paused due to the user.
469   *
470   * @permission ohos.permission.INTERNET
471   * @constant
472   * @syscap SystemCapability.MiscServices.Download
473   * @since 9
474   */
475  /**
476   * Paused code 3 - Indicates that the download is paused due to the user.
477   *
478   * @permission ohos.permission.INTERNET
479   * @constant
480   * @syscap SystemCapability.MiscServices.Download
481   * @crossplatform
482   * @since 10
483   */
484  const PAUSED_BY_USER: number;
485
486  /**
487   * Paused code 4 - Indicates that the download is paused for some reasons.
488   *
489   * @permission ohos.permission.INTERNET
490   * @constant
491   * @syscap SystemCapability.MiscServices.Download
492   * @since 7
493   */
494  /**
495   * Paused code 4 - Indicates that the download is paused for some reasons.
496   *
497   * @permission ohos.permission.INTERNET
498   * @constant
499   * @syscap SystemCapability.MiscServices.Download
500   * @crossplatform
501   * @since 10
502   */
503  const PAUSED_UNKNOWN: number;
504
505  /**
506   * Session status code 0 - Indicates that the download session is completed.
507   *
508   * @permission ohos.permission.INTERNET
509   * @constant
510   * @syscap SystemCapability.MiscServices.Download
511   * @since 7
512   */
513  /**
514   * Session status code 0 - Indicates that the download session is completed.
515   *
516   * @permission ohos.permission.INTERNET
517   * @constant
518   * @syscap SystemCapability.MiscServices.Download
519   * @crossplatform
520   * @since 10
521   */
522  const SESSION_SUCCESSFUL: number;
523
524  /**
525   * Session status code 1 - Indicates that the download session is in progress.
526   *
527   * @permission ohos.permission.INTERNET
528   * @constant
529   * @syscap SystemCapability.MiscServices.Download
530   * @since 7
531   */
532  /**
533   * Session status code 1 - Indicates that the download session is in progress.
534   *
535   * @permission ohos.permission.INTERNET
536   * @constant
537   * @syscap SystemCapability.MiscServices.Download
538   * @crossplatform
539   * @since 10
540   */
541  const SESSION_RUNNING: number;
542
543  /**
544   * Session status code 2 - Indicates that the download session is being scheduled.
545   *
546   * @permission ohos.permission.INTERNET
547   * @constant
548   * @syscap SystemCapability.MiscServices.Download
549   * @since 7
550   */
551  /**
552   * Session status code 2 - Indicates that the download session is being scheduled.
553   *
554   * @permission ohos.permission.INTERNET
555   * @constant
556   * @syscap SystemCapability.MiscServices.Download
557   * @crossplatform
558   * @since 10
559   */
560  const SESSION_PENDING: number;
561
562  /**
563   * Session status code 3 - Indicates that the download session has been paused.
564   *
565   * @permission ohos.permission.INTERNET
566   * @constant
567   * @syscap SystemCapability.MiscServices.Download
568   * @since 7
569   */
570  /**
571   * Session status code 3 - Indicates that the download session has been paused.
572   *
573   * @permission ohos.permission.INTERNET
574   * @constant
575   * @syscap SystemCapability.MiscServices.Download
576   * @crossplatform
577   * @since 10
578   */
579  const SESSION_PAUSED: number;
580
581  /**
582   * Session status code 4 - Indicates that the download session has failed and will not be retried.
583   *
584   * @permission ohos.permission.INTERNET
585   * @constant
586   * @syscap SystemCapability.MiscServices.Download
587   * @since 7
588   */
589  /**
590   * Session status code 4 - Indicates that the download session has failed and will not be retried.
591   *
592   * @permission ohos.permission.INTERNET
593   * @constant
594   * @syscap SystemCapability.MiscServices.Download
595   * @crossplatform
596   * @since 10
597   */
598  const SESSION_FAILED: number;
599
600  /**
601   * Starts a download task.
602   *
603   * @permission ohos.permission.INTERNET
604   * @param { DownloadConfig } config Download config
605   * @param { AsyncCallback<DownloadTask> } callback Indicate the callback function to receive DownloadTask.
606   * @syscap SystemCapability.MiscServices.Download
607   * @FAModelOnly
608   * @since 6
609   * @deprecated since 9
610   * @useinstead ohos.request.downloadFile
611   */
612  function download(config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void;
613
614  /**
615   * Starts a download task.
616   *
617   * @permission ohos.permission.INTERNET
618   * @param { BaseContext } context Indicates the application BaseContext.
619   * @param { DownloadConfig } config Download config
620   * @param { AsyncCallback<DownloadTask> } callback Indicate the callback function to receive DownloadTask.
621   * @throws { BusinessError } 201 - the permissions check fails
622   * @throws { BusinessError } 401 - the parameters check fails
623   * @throws { BusinessError } 13400001 - file operation error
624   * @throws { BusinessError } 13400002 - bad file path
625   * @throws { BusinessError } 13400003 - task service ability error
626   * @syscap SystemCapability.MiscServices.Download
627   * @since 9
628   */
629  /**
630   * Starts a download task.
631   *
632   * @permission ohos.permission.INTERNET
633   * @param { BaseContext } context Indicates the application BaseContext.
634   * @param { DownloadConfig } config Download config
635   * @param { AsyncCallback<DownloadTask> } callback Indicate the callback function to receive DownloadTask.
636   * @throws { BusinessError } 201 - the permissions check fails
637   * @throws { BusinessError } 401 - the parameters check fails
638   * @throws { BusinessError } 13400001 - file operation error
639   * @throws { BusinessError } 13400002 - bad file path
640   * @throws { BusinessError } 13400003 - task service ability error
641   * @syscap SystemCapability.MiscServices.Download
642   * @crossplatform
643   * @since 10
644   */
645  function downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void;
646
647  /**
648   * Starts a download task.
649   *
650   * @permission ohos.permission.INTERNET
651   * @param { DownloadConfig } config Download config
652   * @returns { Promise<DownloadTask> } the promise returned by the function.
653   * @syscap SystemCapability.MiscServices.Download
654   * @FAModelOnly
655   * @since 6
656   * @deprecated since 9
657   * @useinstead ohos.request.downloadFile
658   */
659  function download(config: DownloadConfig): Promise<DownloadTask>;
660
661  /**
662   * Starts a download task.
663   *
664   * @permission ohos.permission.INTERNET
665   * @param { BaseContext } context Indicates the application BaseContext.
666   * @param { DownloadConfig } config Download config
667   * @returns { Promise<DownloadTask> } the promise returned by the function.
668   * @throws { BusinessError } 201 - the permissions check fails
669   * @throws { BusinessError } 401 - the parameters check fails
670   * @throws { BusinessError } 13400001 - file operation error
671   * @throws { BusinessError } 13400002 - bad file path
672   * @throws { BusinessError } 13400003 - task service ability error
673   * @syscap SystemCapability.MiscServices.Download
674   * @since 9
675   */
676  /**
677   * Starts a download task.
678   *
679   * @permission ohos.permission.INTERNET
680   * @param { BaseContext } context Indicates the application BaseContext.
681   * @param { DownloadConfig } config Download config
682   * @returns { Promise<DownloadTask> } the promise returned by the function.
683   * @throws { BusinessError } 201 - the permissions check fails
684   * @throws { BusinessError } 401 - the parameters check fails
685   * @throws { BusinessError } 13400001 - file operation error
686   * @throws { BusinessError } 13400002 - bad file path
687   * @throws { BusinessError } 13400003 - task service ability error
688   * @syscap SystemCapability.MiscServices.Download
689   * @crossplatform
690   * @since 10
691   */
692  function downloadFile(context: BaseContext, config: DownloadConfig): Promise<DownloadTask>;
693
694  /**
695   * Starts a upload task.
696   *
697   * @permission ohos.permission.INTERNET
698   * @param { UploadConfig } config Upload config
699   * @param { AsyncCallback<UploadTask> } callback Indicate the callback function to receive UploadTask.
700   * @syscap SystemCapability.MiscServices.Upload
701   * @FAModelOnly
702   * @since 6
703   * @deprecated since 9
704   * @useinstead ohos.request.uploadFile
705   */
706  function upload(config: UploadConfig, callback: AsyncCallback<UploadTask>): void;
707
708  /**
709   * Starts a upload task.
710   *
711   * @permission ohos.permission.INTERNET
712   * @param { BaseContext } context Indicates the application BaseContext.
713   * @param { UploadConfig } config Upload config
714   * @param { AsyncCallback<UploadTask> } callback Indicate the callback function to receive UploadTask.
715   * @throws { BusinessError } 201 - the permissions check fails
716   * @throws { BusinessError } 401 - the parameters check fails
717   * @throws { BusinessError } 13400002 - bad file path
718   * @syscap SystemCapability.MiscServices.Upload
719   * @since 9
720   */
721  /**
722   * Starts a upload task.
723   *
724   * @permission ohos.permission.INTERNET
725   * @param { BaseContext } context Indicates the application BaseContext.
726   * @param { UploadConfig } config Upload config
727   * @param { AsyncCallback<UploadTask> } callback Indicate the callback function to receive UploadTask.
728   * @throws { BusinessError } 201 - the permissions check fails
729   * @throws { BusinessError } 401 - the parameters check fails
730   * @throws { BusinessError } 13400002 - bad file path
731   * @syscap SystemCapability.MiscServices.Upload
732   * @crossplatform
733   * @since 10
734   */
735  function uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback<UploadTask>): void;
736
737  /**
738   * Starts a upload task.
739   *
740   * @permission ohos.permission.INTERNET
741   * @param { UploadConfig } config Upload config
742   * @returns { Promise<UploadTask> } the promise returned by the function.
743   * @syscap SystemCapability.MiscServices.Upload
744   * @FAModelOnly
745   * @since 6
746   * @deprecated since 9
747   * @useinstead ohos.request.uploadFile
748   */
749  function upload(config: UploadConfig): Promise<UploadTask>;
750
751  /**
752   * Starts a upload task.
753   *
754   * @permission ohos.permission.INTERNET
755   * @param { BaseContext } context Indicates the application BaseContext.
756   * @param { UploadConfig } config Upload config
757   * @returns { Promise<UploadTask> } the promise returned by the function.
758   * @throws { BusinessError } 201 - the permissions check fails
759   * @throws { BusinessError } 401 - the parameters check fails
760   * @throws { BusinessError } 13400002 - bad file path
761   * @syscap SystemCapability.MiscServices.Upload
762   * @since 9
763   */
764  /**
765   * Starts a upload task.
766   *
767   * @permission ohos.permission.INTERNET
768   * @param { BaseContext } context Indicates the application BaseContext.
769   * @param { UploadConfig } config Upload config
770   * @returns { Promise<UploadTask> } the promise returned by the function.
771   * @throws { BusinessError } 201 - the permissions check fails
772   * @throws { BusinessError } 401 - the parameters check fails
773   * @throws { BusinessError } 13400002 - bad file path
774   * @syscap SystemCapability.MiscServices.Upload
775   * @crossplatform
776   * @since 10
777   */
778  function uploadFile(context: BaseContext, config: UploadConfig): Promise<UploadTask>;
779
780  /**
781   * DownloadConfig data Structure
782   *
783   * @interface DownloadConfig
784   * @permission ohos.permission.INTERNET
785   * @syscap SystemCapability.MiscServices.Download
786   * @since 6
787   * @name DownloadConfig
788   */
789  /**
790   * DownloadConfig data Structure
791   *
792   * @typedef DownloadConfig
793   * @permission ohos.permission.INTERNET
794   * @syscap SystemCapability.MiscServices.Download
795   * @crossplatform
796   * @since 10
797   * @name DownloadConfig
798   */
799  interface DownloadConfig {
800    /**
801     * Resource address.
802     *
803     * @permission ohos.permission.INTERNET
804     * @syscap SystemCapability.MiscServices.Download
805     * @since 6
806     */
807    /**
808     * Resource address.
809     *
810     * @permission ohos.permission.INTERNET
811     * @type { string }
812     * @syscap SystemCapability.MiscServices.Download
813     * @crossplatform
814     * @since 10
815     */
816    url: string;
817    /**
818     * Adds an HTTP or HTTPS header to be included with the download request.
819     *
820     * @permission ohos.permission.INTERNET
821     * @syscap SystemCapability.MiscServices.Download
822     * @since 6
823     */
824    /**
825     * Adds an HTTP or HTTPS header to be included with the download request.
826     *
827     * @permission ohos.permission.INTERNET
828     * @type { ?Object }
829     * @syscap SystemCapability.MiscServices.Download
830     * @crossplatform
831     * @since 10
832     */
833    header?: Object;
834    /**
835     * Allows download under a metered connection.
836     *
837     * @permission ohos.permission.INTERNET
838     * @syscap SystemCapability.MiscServices.Download
839     * @since 6
840     */
841    /**
842     * Allows download under a metered connection.
843     *
844     * @permission ohos.permission.INTERNET
845     * @type { ?boolean }
846     * @syscap SystemCapability.MiscServices.Download
847     * @crossplatform
848     * @since 10
849     */
850    enableMetered?: boolean;
851    /**
852     * Allows download in a roaming network.
853     *
854     * @permission ohos.permission.INTERNET
855     * @syscap SystemCapability.MiscServices.Download
856     * @since 6
857     */
858    /**
859     * Allows download in a roaming network.
860     *
861     * @permission ohos.permission.INTERNET
862     * @type { ?boolean }
863     * @syscap SystemCapability.MiscServices.Download
864     * @crossplatform
865     * @since 10
866     */
867    enableRoaming?: boolean;
868    /**
869     * Sets the description of a download session.
870     *
871     * @permission ohos.permission.INTERNET
872     * @syscap SystemCapability.MiscServices.Download
873     * @since 6
874     */
875    /**
876     * Sets the description of a download session.
877     *
878     * @permission ohos.permission.INTERNET
879     * @type { ?string }
880     * @syscap SystemCapability.MiscServices.Download
881     * @crossplatform
882     * @since 10
883     */
884    description?: string;
885    /**
886     * Sets the network type allowed for download.
887     *
888     * @permission ohos.permission.INTERNET
889     * @syscap SystemCapability.MiscServices.Download
890     * @since 6
891     */
892    /**
893     * Sets the network type allowed for download.
894     *
895     * @permission ohos.permission.INTERNET
896     * @type { ?number }
897     * @syscap SystemCapability.MiscServices.Download
898     * @crossplatform
899     * @since 10
900     */
901    networkType?: number;
902    /**
903     * Sets the path for downloads.
904     *
905     * @permission ohos.permission.INTERNET
906     * @syscap SystemCapability.MiscServices.Download
907     * @since 7
908     */
909    /**
910     * Sets the path for downloads.
911     *
912     * @permission ohos.permission.INTERNET
913     * @type { ?string }
914     * @syscap SystemCapability.MiscServices.Download
915     * @crossplatform
916     * @since 10
917     */
918    filePath?: string;
919    /**
920     * Sets a download session title.
921     *
922     * @permission ohos.permission.INTERNET
923     * @syscap SystemCapability.MiscServices.Download
924     * @since 6
925     */
926    /**
927     * Sets a download session title.
928     *
929     * @permission ohos.permission.INTERNET
930     * @type { ?string }
931     * @syscap SystemCapability.MiscServices.Download
932     * @crossplatform
933     * @since 10
934     */
935    title?: string;
936    /**
937     * Allow download background task notifications.
938     *
939     * @permission ohos.permission.INTERNET
940     * @syscap SystemCapability.MiscServices.Download
941     * @since 9
942     */
943    /**
944     * Allow download background task notifications.
945     *
946     * @permission ohos.permission.INTERNET
947     * @type { ?boolean }
948     * @syscap SystemCapability.MiscServices.Download
949     * @crossplatform
950     * @since 10
951     */
952    background?: boolean;
953  }
954
955  /**
956   * DownloadInfo data Structure
957   *
958   * @interface DownloadInfo
959   * @permission ohos.permission.INTERNET
960   * @syscap SystemCapability.MiscServices.Download
961   * @since 7
962   * @name DownloadInfo
963   */
964  /**
965   * DownloadInfo data Structure
966   *
967   * @typedef DownloadInfo
968   * @permission ohos.permission.INTERNET
969   * @syscap SystemCapability.MiscServices.Download
970   * @crossplatform
971   * @since 10
972   */
973  interface DownloadInfo {
974    /**
975     * the description of a file to be downloaded.
976     *
977     * @permission ohos.permission.INTERNET
978     * @syscap SystemCapability.MiscServices.Download
979     * @since 7
980     */
981    /**
982     * the description of a file to be downloaded.
983     *
984     * @permission ohos.permission.INTERNET
985     * @type { string }
986     * @syscap SystemCapability.MiscServices.Download
987     * @crossplatform
988     * @since 10
989     */
990    description: string;
991    /**
992     * the real-time downloads size (in bytes).
993     *
994     * @permission ohos.permission.INTERNET
995     * @syscap SystemCapability.MiscServices.Download
996     * @since 7
997     */
998    /**
999     * the real-time downloads size (in bytes).
1000     *
1001     * @permission ohos.permission.INTERNET
1002     * @type { number }
1003     * @syscap SystemCapability.MiscServices.Download
1004     * @crossplatform
1005     * @since 10
1006     */
1007    downloadedBytes: number;
1008    /**
1009     * the ID of a file to be downloaded.
1010     *
1011     * @permission ohos.permission.INTERNET
1012     * @syscap SystemCapability.MiscServices.Download
1013     * @since 7
1014     */
1015    /**
1016     * the ID of a file to be downloaded.
1017     *
1018     * @permission ohos.permission.INTERNET
1019     * @type { number }
1020     * @syscap SystemCapability.MiscServices.Download
1021     * @crossplatform
1022     * @since 10
1023     */
1024    downloadId: number;
1025    /**
1026     * a download failure cause, which can be any DownloadSession.ERROR_* constant.
1027     *
1028     * @permission ohos.permission.INTERNET
1029     * @syscap SystemCapability.MiscServices.Download
1030     * @since 7
1031     */
1032    /**
1033     * a download failure cause, which can be any DownloadSession.ERROR_* constant.
1034     *
1035     * @permission ohos.permission.INTERNET
1036     * @type { number }
1037     * @syscap SystemCapability.MiscServices.Download
1038     * @crossplatform
1039     * @since 10
1040     */
1041    failedReason: number;
1042    /**
1043     * the name of a file to be downloaded.
1044     *
1045     * @permission ohos.permission.INTERNET
1046     * @syscap SystemCapability.MiscServices.Download
1047     * @since 7
1048     */
1049    /**
1050     * the name of a file to be downloaded.
1051     *
1052     * @permission ohos.permission.INTERNET
1053     * @type { string }
1054     * @syscap SystemCapability.MiscServices.Download
1055     * @crossplatform
1056     * @since 10
1057     */
1058    fileName: string;
1059    /**
1060     * the URI of a stored file.
1061     *
1062     * @permission ohos.permission.INTERNET
1063     * @syscap SystemCapability.MiscServices.Download
1064     * @since 7
1065     */
1066    /**
1067     * the URI of a stored file.
1068     *
1069     * @permission ohos.permission.INTERNET
1070     * @type { string }
1071     * @syscap SystemCapability.MiscServices.Download
1072     * @crossplatform
1073     * @since 10
1074     */
1075    filePath: string;
1076    /**
1077     * the reason why a session is paused, which can be any DownloadSession.PAUSED_* constant.
1078     *
1079     * @permission ohos.permission.INTERNET
1080     * @syscap SystemCapability.MiscServices.Download
1081     * @since 7
1082     */
1083    /**
1084     * the reason why a session is paused, which can be any DownloadSession.PAUSED_* constant.
1085     *
1086     * @permission ohos.permission.INTERNET
1087     * @type { number }
1088     * @syscap SystemCapability.MiscServices.Download
1089     * @crossplatform
1090     * @since 10
1091     */
1092    pausedReason: number;
1093    /**
1094     * the download status code, which can be any DownloadSession.SESSION_* constant.
1095     *
1096     * @permission ohos.permission.INTERNET
1097     * @syscap SystemCapability.MiscServices.Download
1098     * @since 7
1099     */
1100    /**
1101     * the download status code, which can be any DownloadSession.SESSION_* constant.
1102     *
1103     * @permission ohos.permission.INTERNET
1104     * @type { number }
1105     * @syscap SystemCapability.MiscServices.Download
1106     * @crossplatform
1107     * @since 10
1108     */
1109    status: number;
1110    /**
1111     * the URI of files to be downloaded.
1112     *
1113     * @permission ohos.permission.INTERNET
1114     * @syscap SystemCapability.MiscServices.Download
1115     * @since 7
1116     */
1117    /**
1118     * the URI of files to be downloaded.
1119     *
1120     * @permission ohos.permission.INTERNET
1121     * @type { string }
1122     * @syscap SystemCapability.MiscServices.Download
1123     * @crossplatform
1124     * @since 10
1125     */
1126    targetURI: string;
1127    /**
1128     * the title of a file to be downloaded.
1129     *
1130     * @permission ohos.permission.INTERNET
1131     * @syscap SystemCapability.MiscServices.Download
1132     * @since 7
1133     */
1134    /**
1135     * the title of a file to be downloaded.
1136     *
1137     * @permission ohos.permission.INTERNET
1138     * @type { string }
1139     * @syscap SystemCapability.MiscServices.Download
1140     * @crossplatform
1141     * @since 10
1142     */
1143    downloadTitle: string;
1144    /**
1145     * the total size of files to be downloaded (in bytes).
1146     *
1147     * @permission ohos.permission.INTERNET
1148     * @syscap SystemCapability.MiscServices.Download
1149     * @since 7
1150     */
1151    /**
1152     * the total size of files to be downloaded (in bytes).
1153     *
1154     * @permission ohos.permission.INTERNET
1155     * @type { number }
1156     * @syscap SystemCapability.MiscServices.Download
1157     * @crossplatform
1158     * @since 10
1159     */
1160    downloadTotalBytes: number;
1161  }
1162
1163  /**
1164   * Download task interface
1165   *
1166   * @interface DownloadTask
1167   * @permission ohos.permission.INTERNET
1168   * @syscap SystemCapability.MiscServices.Download
1169   * @since 6
1170   */
1171  /**
1172   * Download task interface
1173   *
1174   * @typedef DownloadTask
1175   * @permission ohos.permission.INTERNET
1176   * @syscap SystemCapability.MiscServices.Download
1177   * @crossplatform
1178   * @since 10
1179   */
1180  interface DownloadTask {
1181    /**
1182     * Called when the current download session is in process.
1183     *
1184     * @permission ohos.permission.INTERNET
1185     * @param { 'progress' } type progress Indicates the download task progress.
1186     * @param { function } callback
1187     *        The callback function for the download progress change event
1188     *        receivedSize the length of downloaded data, in bytes
1189     *        totalSize he length of data expected to be downloaded, in bytes.
1190     * @syscap SystemCapability.MiscServices.Download
1191     * @since 6
1192     */
1193    /**
1194     * Called when the current download session is in process.
1195     *
1196     * @permission ohos.permission.INTERNET
1197     * @param { 'progress' } type progress Indicates the download task progress.
1198     * @param { function } callback
1199     *        The callback function for the download progress change event
1200     *        receivedSize the length of downloaded data, in bytes
1201     *        totalSize he length of data expected to be downloaded, in bytes.
1202     * @syscap SystemCapability.MiscServices.Download
1203     * @crossplatform
1204     * @since 10
1205     */
1206    on(type: 'progress', callback: (receivedSize: number, totalSize: number) => void): void;
1207
1208    /**
1209     * Called when the current download session is in process.
1210     *
1211     * @permission ohos.permission.INTERNET
1212     * @param { 'progress' } type progress Indicates the download task progress.
1213     * @param { function } [callback]
1214     *        The callback function for the download progress change event
1215     *        receivedSize the length of downloaded data, in bytes
1216     *        totalSize he length of data expected to be downloaded, in bytes.
1217     * @syscap SystemCapability.MiscServices.Download
1218     * @since 6
1219     */
1220    /**
1221     * Called when the current download session is in process.
1222     *
1223     * @permission ohos.permission.INTERNET
1224     * @param { 'progress' } type progress Indicates the download task progress.
1225     * @param { function } [callback]
1226     *        The callback function for the download progress change event
1227     *        receivedSize the length of downloaded data, in bytes
1228     *        totalSize he length of data expected to be downloaded, in bytes.
1229     * @syscap SystemCapability.MiscServices.Download
1230     * @crossplatform
1231     * @since 10
1232     */
1233    off(type: 'progress', callback?: (receivedSize: number, totalSize: number) => void): void;
1234
1235    /**
1236     * Called when the current download session complete pause or remove.
1237     *
1238     * @permission ohos.permission.INTERNET
1239     * @param { 'complete' | 'pause' | 'remove' } type Indicates the download session event type
1240     *        complete: download task completed,
1241     *        pause: download task stopped,
1242     *        remove: download task deleted.
1243     * @param { function } callback The callback function for the download complete pause or remove change event.
1244     * @syscap SystemCapability.MiscServices.Download
1245     * @since 7
1246     */
1247    /**
1248     * Called when the current download session complete pause or remove.
1249     *
1250     * @permission ohos.permission.INTERNET
1251     * @param { 'complete' | 'pause' | 'remove' } type Indicates the download session event type
1252     *        complete: download task completed,
1253     *        pause: download task stopped,
1254     *        remove: download task deleted.
1255     * @param { function } callback The callback function for the download complete pause or remove change event.
1256     * @syscap SystemCapability.MiscServices.Download
1257     * @crossplatform
1258     * @since 10
1259     */
1260    on(type: 'complete' | 'pause' | 'remove', callback: () => void): void;
1261
1262    /**
1263     * Called when the current download session complete pause or remove.
1264     *
1265     * @permission ohos.permission.INTERNET
1266     * @param { 'complete' | 'pause' | 'remove' } type Indicates the download session event type
1267     *        complete: download task completed,
1268     *        pause: download task stopped,
1269     *        remove: download task deleted.
1270     * @param { function } [callback] The callback function for the download complete pause or remove change event.
1271     * @syscap SystemCapability.MiscServices.Download
1272     * @since 7
1273     */
1274    /**
1275     * Called when the current download session complete pause or remove.
1276     *
1277     * @permission ohos.permission.INTERNET
1278     * @param { 'complete' | 'pause' | 'remove' } type Indicates the download session event type
1279     *        complete: download task completed,
1280     *        pause: download task stopped,
1281     *        remove: download task deleted.
1282     * @param { function } [callback] The callback function for the download complete pause or remove change event.
1283     * @syscap SystemCapability.MiscServices.Download
1284     * @crossplatform
1285     * @since 10
1286     */
1287    off(type: 'complete' | 'pause' | 'remove', callback?: () => void): void;
1288
1289    /**
1290     * Called when the current download session fails.
1291     *
1292     * @permission ohos.permission.INTERNET
1293     * @param { 'fail' } type Indicates the download session type, fail: download task has failed.
1294     * @param { function } callback The callback function for the download fail change event
1295     *        err The error code for download task.
1296     * @syscap SystemCapability.MiscServices.Download
1297     * @since 7
1298     */
1299    /**
1300     * Called when the current download session fails.
1301     *
1302     * @permission ohos.permission.INTERNET
1303     * @param { 'fail' } type Indicates the download session type, fail: download task has failed.
1304     * @param { function } callback The callback function for the download fail change event
1305     *        err The error code for download task.
1306     * @syscap SystemCapability.MiscServices.Download
1307     * @crossplatform
1308     * @since 10
1309     */
1310    on(type: 'fail', callback: (err: number) => void): void;
1311
1312    /**
1313     * Called when the current download session fails.
1314     *
1315     * @permission ohos.permission.INTERNET
1316     * @param { 'fail' } type Indicates the download session type, fail: download task has failed.
1317     * @param { function } [callback] Indicate the callback function to receive err.
1318     *        err The error code for download task.
1319     * @syscap SystemCapability.MiscServices.Download
1320     * @since 7
1321     */
1322    /**
1323     * Called when the current download session fails.
1324     *
1325     * @permission ohos.permission.INTERNET
1326     * @param { 'fail' } type Indicates the download session type, fail: download task has failed.
1327     * @param { function } [callback] Indicate the callback function to receive err.
1328     *        err The error code for download task.
1329     * @syscap SystemCapability.MiscServices.Download
1330     * @crossplatform
1331     * @since 10
1332     */
1333    off(type: 'fail', callback?: (err: number) => void): void;
1334
1335    /**
1336     * Deletes a download session and the downloaded files.
1337     *
1338     * @permission ohos.permission.INTERNET
1339     * @param { AsyncCallback<boolean> } callback Indicates asynchronous invoking Result.
1340     * @syscap SystemCapability.MiscServices.Download
1341     * @since 6
1342     * @deprecated since 9
1343     * @useinstead ohos.request.delete
1344     */
1345    remove(callback: AsyncCallback<boolean>): void;
1346
1347    /**
1348     * Deletes a download session and the downloaded files.
1349     *
1350     * @permission ohos.permission.INTERNET
1351     * @returns { Promise<boolean> } the promise returned by the function.
1352     * @syscap SystemCapability.MiscServices.Download
1353     * @since 6
1354     * @deprecated since 9
1355     * @useinstead ohos.request.delete
1356     */
1357    remove(): Promise<boolean>;
1358
1359    /**
1360     * Pause a download session.
1361     *
1362     * @permission ohos.permission.INTERNET
1363     * @param { AsyncCallback<void> } callback Indicates asynchronous invoking Result.
1364     * @syscap SystemCapability.MiscServices.Download
1365     * @since 7
1366     * @deprecated since 9
1367     * @useinstead ohos.request.suspend
1368     */
1369    pause(callback: AsyncCallback<void>): void;
1370
1371    /**
1372     * Pause a download session.
1373     *
1374     * @permission ohos.permission.INTERNET
1375     * @returns { Promise<void> } the promise returned by the function.
1376     * @syscap SystemCapability.MiscServices.Download
1377     * @since 7
1378     * @deprecated since 9
1379     * @useinstead ohos.request.suspend
1380     */
1381    pause(): Promise<void>;
1382
1383    /**
1384     * Resume a paused download session.
1385     *
1386     * @permission ohos.permission.INTERNET
1387     * @param { AsyncCallback<void> } callback Indicates asynchronous invoking Result.
1388     * @syscap SystemCapability.MiscServices.Download
1389     * @since 7
1390     * @deprecated since 9
1391     * @useinstead ohos.request.restore
1392     */
1393    resume(callback: AsyncCallback<void>): void;
1394
1395    /**
1396     * Resume a paused download session.
1397     *
1398     * @permission ohos.permission.INTERNET
1399     * @returns { Promise<void> } the promise returned by the function.
1400     * @syscap SystemCapability.MiscServices.Download
1401     * @since 7
1402     * @deprecated since 9
1403     * @useinstead ohos.request.restore
1404     */
1405    resume(): Promise<void>;
1406
1407    /**
1408     * Queries download information of a session, which is defined in DownloadSession.DownloadInfo.
1409     *
1410     * @permission ohos.permission.INTERNET
1411     * @param { AsyncCallback<DownloadInfo> } callback Indicate the callback function to receive download info.
1412     * @syscap SystemCapability.MiscServices.Download
1413     * @since 7
1414     * @deprecated since 9
1415     * @useinstead ohos.request.getTaskInfo
1416     */
1417    query(callback: AsyncCallback<DownloadInfo>): void;
1418
1419    /**
1420     * Queries download information of a session, which is defined in DownloadSession.DownloadInfo.
1421     *
1422     * @permission ohos.permission.INTERNET
1423     * @returns { Promise<DownloadInfo> } the promise returned by the function.
1424     * @syscap SystemCapability.MiscServices.Download
1425     * @since 7
1426     * @deprecated since 9
1427     * @useinstead ohos.request.getTaskInfo
1428     */
1429    query(): Promise<DownloadInfo>;
1430
1431    /**
1432     * Queries the MIME type of the download file.
1433     *
1434     * @permission ohos.permission.INTERNET
1435     * @param { AsyncCallback<string> } callback Indicate the callback function to receive download file MIME type.
1436     * @syscap SystemCapability.MiscServices.Download
1437     * @since 7
1438     * @deprecated since 9
1439     * @useinstead ohos.request.getTaskMimeType
1440     */
1441    queryMimeType(callback: AsyncCallback<string>): void;
1442
1443    /**
1444     * Queries the MIME type of the download file.
1445     *
1446     * @permission ohos.permission.INTERNET
1447     * @returns { Promise<string> } the promise returned by the function.
1448     * @syscap SystemCapability.MiscServices.Download
1449     * @since 7
1450     * @deprecated since 9
1451     * @useinstead ohos.request.getTaskMimeType
1452     */
1453    queryMimeType(): Promise<string>;
1454
1455    /**
1456     * Delete the download task
1457     *
1458     * @permission ohos.permission.INTERNET
1459     * @param { AsyncCallback<boolean> } callback
1460     * @throws { BusinessError } 201 - the permissions check fails
1461     * @throws { BusinessError } 401 - the parameters check fails
1462     * @syscap SystemCapability.MiscServices.Download
1463     * @since 9
1464     */
1465    /**
1466     * Delete the download task
1467     *
1468     * @permission ohos.permission.INTERNET
1469     * @param { AsyncCallback<boolean> } callback
1470     * @throws { BusinessError } 201 - the permissions check fails
1471     * @throws { BusinessError } 401 - the parameters check fails
1472     * @syscap SystemCapability.MiscServices.Download
1473     * @crossplatform
1474     * @since 10
1475     */
1476    delete(callback: AsyncCallback<boolean>): void;
1477
1478    /**
1479     * Delete the download task
1480     *
1481     * @permission ohos.permission.INTERNET
1482     * @returns { Promise<boolean> } the promise returned by the function.
1483     * @throws { BusinessError } 201 - the permissions check fails
1484     * @throws { BusinessError } 401 - the parameters check fails
1485     * @syscap SystemCapability.MiscServices.Download
1486     * @since 9
1487     */
1488    /**
1489     * Delete the download task
1490     *
1491     * @permission ohos.permission.INTERNET
1492     * @returns { Promise<boolean> } the promise returned by the function.
1493     * @throws { BusinessError } 201 - the permissions check fails
1494     * @throws { BusinessError } 401 - the parameters check fails
1495     * @syscap SystemCapability.MiscServices.Download
1496     * @crossplatform
1497     * @since 10
1498     */
1499    delete(): Promise<boolean>;
1500
1501    /**
1502     * Suspend the download task
1503     *
1504     * @permission ohos.permission.INTERNET
1505     * @param { AsyncCallback<boolean> } callback
1506     * @throws { BusinessError } 201 - the permissions check fails
1507     * @throws { BusinessError } 401 - the parameters check fails
1508     * @syscap SystemCapability.MiscServices.Download
1509     * @since 9
1510     */
1511    /**
1512     * Suspend the download task
1513     *
1514     * @permission ohos.permission.INTERNET
1515     * @param { AsyncCallback<boolean> } callback
1516     * @throws { BusinessError } 201 - the permissions check fails
1517     * @throws { BusinessError } 401 - the parameters check fails
1518     * @syscap SystemCapability.MiscServices.Download
1519     * @crossplatform
1520     * @since 10
1521     */
1522    suspend(callback: AsyncCallback<boolean>): void;
1523
1524    /**
1525     * Suspend the download task
1526     *
1527     * @permission ohos.permission.INTERNET
1528     * @returns { Promise<boolean> } the promise returned by the function.
1529     * @throws { BusinessError } 201 - the permissions check fails
1530     * @throws { BusinessError } 401 - the parameters check fails
1531     * @syscap SystemCapability.MiscServices.Download
1532     * @since 9
1533     */
1534    /**
1535     * Suspend the download task
1536     *
1537     * @permission ohos.permission.INTERNET
1538     * @returns { Promise<boolean> } the promise returned by the function.
1539     * @throws { BusinessError } 201 - the permissions check fails
1540     * @throws { BusinessError } 401 - the parameters check fails
1541     * @syscap SystemCapability.MiscServices.Download
1542     * @crossplatform
1543     * @since 10
1544     */
1545    suspend(): Promise<boolean>;
1546
1547    /**
1548     * Restore the download task
1549     *
1550     * @permission ohos.permission.INTERNET
1551     * @param { AsyncCallback<boolean> } callback
1552     * @throws { BusinessError } 201 - the permissions check fails
1553     * @throws { BusinessError } 401 - the parameters check fails
1554     * @syscap SystemCapability.MiscServices.Download
1555     * @since 9
1556     */
1557    /**
1558     * Restore the download task
1559     *
1560     * @permission ohos.permission.INTERNET
1561     * @param { AsyncCallback<boolean> } callback
1562     * @throws { BusinessError } 201 - the permissions check fails
1563     * @throws { BusinessError } 401 - the parameters check fails
1564     * @syscap SystemCapability.MiscServices.Download
1565     * @crossplatform
1566     * @since 10
1567     */
1568    restore(callback: AsyncCallback<boolean>): void;
1569
1570    /**
1571     * Restore the download task
1572     *
1573     * @permission ohos.permission.INTERNET
1574     * @returns { Promise<boolean> } the promise returned by the function.
1575     * @throws { BusinessError } 201 - the permissions check fails
1576     * @throws { BusinessError } 401 - the parameters check fails
1577     * @syscap SystemCapability.MiscServices.Download
1578     * @since 9
1579     */
1580    /**
1581     * Restore the download task
1582     *
1583     * @permission ohos.permission.INTERNET
1584     * @returns { Promise<boolean> } the promise returned by the function.
1585     * @throws { BusinessError } 201 - the permissions check fails
1586     * @throws { BusinessError } 401 - the parameters check fails
1587     * @syscap SystemCapability.MiscServices.Download
1588     * @crossplatform
1589     * @since 10
1590     */
1591    restore(): Promise<boolean>;
1592
1593    /**
1594     * Get the download task info
1595     *
1596     * @permission ohos.permission.INTERNET
1597     * @param { AsyncCallback<DownloadInfo> } callback
1598     * @throws { BusinessError } 201 - the permissions check fails
1599     * @throws { BusinessError } 401 - the parameters check fails
1600     * @syscap SystemCapability.MiscServices.Download
1601     * @since 9
1602     */
1603    /**
1604     * Get the download task info
1605     *
1606     * @permission ohos.permission.INTERNET
1607     * @param { AsyncCallback<DownloadInfo> } callback
1608     * @throws { BusinessError } 201 - the permissions check fails
1609     * @throws { BusinessError } 401 - the parameters check fails
1610     * @syscap SystemCapability.MiscServices.Download
1611     * @crossplatform
1612     * @since 10
1613     */
1614    getTaskInfo(callback: AsyncCallback<DownloadInfo>): void;
1615
1616    /**
1617     * Get the download task info
1618     *
1619     * @permission ohos.permission.INTERNET
1620     * @returns { Promise<DownloadInfo> } the promise returned by the function.
1621     * @throws { BusinessError } 201 - the permissions check fails
1622     * @throws { BusinessError } 401 - the parameters check fails
1623     * @syscap SystemCapability.MiscServices.Download
1624     * @since 9
1625     */
1626    /**
1627     * Get the download task info
1628     *
1629     * @permission ohos.permission.INTERNET
1630     * @returns { Promise<DownloadInfo> } the promise returned by the function.
1631     * @throws { BusinessError } 201 - the permissions check fails
1632     * @throws { BusinessError } 401 - the parameters check fails
1633     * @syscap SystemCapability.MiscServices.Download
1634     * @crossplatform
1635     * @since 10
1636     */
1637    getTaskInfo(): Promise<DownloadInfo>;
1638
1639    /**
1640     * Get mimetype of the download task
1641     *
1642     * @permission ohos.permission.INTERNET
1643     * @param { AsyncCallback<string> } callback
1644     * @throws { BusinessError } 201 - the permissions check fails
1645     * @throws { BusinessError } 401 - the parameters check fails
1646     * @syscap SystemCapability.MiscServices.Download
1647     * @since 9
1648     */
1649    /**
1650     * Get mimetype of the download task
1651     *
1652     * @permission ohos.permission.INTERNET
1653     * @param { AsyncCallback<string> } callback
1654     * @throws { BusinessError } 201 - the permissions check fails
1655     * @throws { BusinessError } 401 - the parameters check fails
1656     * @syscap SystemCapability.MiscServices.Download
1657     * @crossplatform
1658     * @since 10
1659     */
1660    getTaskMimeType(callback: AsyncCallback<string>): void;
1661
1662    /**
1663     * Get mimetype of the download task
1664     *
1665     * @permission ohos.permission.INTERNET
1666     * @returns { Promise<string> } the promise returned by the function.
1667     * @throws { BusinessError } 201 - the permissions check fails
1668     * @throws { BusinessError } 401 - the parameters check fails
1669     * @syscap SystemCapability.MiscServices.Download
1670     * @since 9
1671     */
1672    /**
1673     * Get mimetype of the download task
1674     *
1675     * @permission ohos.permission.INTERNET
1676     * @returns { Promise<string> } the promise returned by the function.
1677     * @throws { BusinessError } 201 - the permissions check fails
1678     * @throws { BusinessError } 401 - the parameters check fails
1679     * @syscap SystemCapability.MiscServices.Download
1680     * @crossplatform
1681     * @since 10
1682     */
1683    getTaskMimeType(): Promise<string>;
1684  }
1685
1686  /**
1687   * File data Structure
1688   *
1689   * @interface File
1690   * @permission ohos.permission.INTERNET
1691   * @syscap SystemCapability.MiscServices.Download
1692   * @since 6
1693   * @name File
1694   */
1695  /**
1696   * File data Structure
1697   *
1698   * @typedef File
1699   * @permission ohos.permission.INTERNET
1700   * @syscap SystemCapability.MiscServices.Download
1701   * @crossplatform
1702   * @since 10
1703   */
1704  interface File {
1705    /**
1706     * When multipart is submitted, the file name in the request header.
1707     *
1708     * @permission ohos.permission.INTERNET
1709     * @syscap SystemCapability.MiscServices.Download
1710     * @since 6
1711     */
1712    /**
1713     * When multipart is submitted, the file name in the request header.
1714     *
1715     * @permission ohos.permission.INTERNET
1716     * @type { string }
1717     * @syscap SystemCapability.MiscServices.Download
1718     * @crossplatform
1719     * @since 10
1720     */
1721    filename: string;
1722    /**
1723     * When multipart is submitted, the name of the form item. The default is file.
1724     *
1725     * @permission ohos.permission.INTERNET
1726     * @syscap SystemCapability.MiscServices.Download
1727     * @since 6
1728     */
1729    /**
1730     * When multipart is submitted, the name of the form item. The default is file.
1731     *
1732     * @permission ohos.permission.INTERNET
1733     * @type { string }
1734     * @syscap SystemCapability.MiscServices.Download
1735     * @crossplatform
1736     * @since 10
1737     */
1738    name: string;
1739    /**
1740     * The local storage path of the file (please refer to the storage directory definition for path usage).
1741     *
1742     * @permission ohos.permission.INTERNET
1743     * @syscap SystemCapability.MiscServices.Download
1744     * @since 6
1745     */
1746    /**
1747     * The local storage path of the file (please refer to the storage directory definition for path usage).
1748     *
1749     * @permission ohos.permission.INTERNET
1750     * @type { string }
1751     * @syscap SystemCapability.MiscServices.Download
1752     * @crossplatform
1753     * @since 10
1754     */
1755    uri: string;
1756    /**
1757     * The content type of the file is obtained by default according to the suffix of the file name or path.
1758     *
1759     * @permission ohos.permission.INTERNET
1760     * @syscap SystemCapability.MiscServices.Download
1761     * @since 6
1762     */
1763    /**
1764     * The content type of the file is obtained by default according to the suffix of the file name or path.
1765     *
1766     * @permission ohos.permission.INTERNET
1767     * @type { string }
1768     * @syscap SystemCapability.MiscServices.Download
1769     * @crossplatform
1770     * @since 10
1771     */
1772    type: string;
1773  }
1774
1775  /**
1776   * RequestData data Structure
1777   *
1778   * @interface RequestData
1779   * @permission ohos.permission.INTERNET
1780   * @syscap SystemCapability.MiscServices.Download
1781   * @since 6
1782   * @name RequestData
1783   */
1784  /**
1785   * RequestData data Structure
1786   *
1787   * @typedef RequestData
1788   * @permission ohos.permission.INTERNET
1789   * @syscap SystemCapability.MiscServices.Download
1790   * @crossplatform
1791   * @since 10
1792   */
1793  interface RequestData {
1794    /**
1795     * Represents the name of the form element.
1796     *
1797     * @permission ohos.permission.INTERNET
1798     * @syscap SystemCapability.MiscServices.Download
1799     * @since 6
1800     */
1801    /**
1802     * Represents the name of the form element.
1803     *
1804     * @permission ohos.permission.INTERNET
1805     * @type { string }
1806     * @syscap SystemCapability.MiscServices.Download
1807     * @crossplatform
1808     * @since 10
1809     */
1810    name: string;
1811    /**
1812     * Represents the value of the form element.
1813     *
1814     * @permission ohos.permission.INTERNET
1815     * @syscap SystemCapability.MiscServices.Download
1816     * @since 6
1817     */
1818    /**
1819     * Represents the value of the form element.
1820     *
1821     * @permission ohos.permission.INTERNET
1822     * @type { string }
1823     * @syscap SystemCapability.MiscServices.Download
1824     * @crossplatform
1825     * @since 10
1826     */
1827    value: string;
1828  }
1829
1830  /**
1831   * UploadConfig data Structure
1832   *
1833   * @interface UploadConfig
1834   * @permission ohos.permission.INTERNET
1835   * @syscap SystemCapability.MiscServices.Upload
1836   * @since 6
1837   * @name UploadConfig
1838   */
1839  /**
1840   * UploadConfig data Structure
1841   *
1842   * @typedef UploadConfig
1843   * @permission ohos.permission.INTERNET
1844   * @syscap SystemCapability.MiscServices.Upload
1845   * @crossplatform
1846   * @since 10
1847   */
1848  interface UploadConfig {
1849    /**
1850     * Resource address.
1851     *
1852     * @permission ohos.permission.INTERNET
1853     * @syscap SystemCapability.MiscServices.Upload
1854     * @since 6
1855     */
1856    /**
1857     * Resource address.
1858     *
1859     * @permission ohos.permission.INTERNET
1860     * @type { string }
1861     * @syscap SystemCapability.MiscServices.Upload
1862     * @crossplatform
1863     * @since 10
1864     */
1865    url: string;
1866    /**
1867     * Adds an HTTP or HTTPS header to be included with the upload request.
1868     *
1869     * @permission ohos.permission.INTERNET
1870     * @syscap SystemCapability.MiscServices.Upload
1871     * @since 6
1872     */
1873    /**
1874     * Adds an HTTP or HTTPS header to be included with the upload request.
1875     *
1876     * @permission ohos.permission.INTERNET
1877     * @type { Object }
1878     * @syscap SystemCapability.MiscServices.Upload
1879     * @crossplatform
1880     * @since 10
1881     */
1882    header: Object;
1883    /**
1884     * Request method: POST, PUT. The default POST.
1885     *
1886     * @permission ohos.permission.INTERNET
1887     * @syscap SystemCapability.MiscServices.Upload
1888     * @since 6
1889     */
1890    /**
1891     * Request method: POST, PUT. The default POST.
1892     *
1893     * @permission ohos.permission.INTERNET
1894     * @type { string }
1895     * @syscap SystemCapability.MiscServices.Upload
1896     * @crossplatform
1897     * @since 10
1898     */
1899    method: string;
1900    /**
1901     * A list of files to be uploaded. Please use multipart/form-data to submit.
1902     *
1903     * @permission ohos.permission.INTERNET
1904     * @syscap SystemCapability.MiscServices.Upload
1905     * @since 6
1906     */
1907    /**
1908     * A list of files to be uploaded. Please use multipart/form-data to submit.
1909     *
1910     * @permission ohos.permission.INTERNET
1911     * @type { Array<File> }
1912     * @syscap SystemCapability.MiscServices.Upload
1913     * @crossplatform
1914     * @since 10
1915     */
1916    files: Array<File>;
1917    /**
1918     * The requested form data.
1919     *
1920     * @permission ohos.permission.INTERNET
1921     * @syscap SystemCapability.MiscServices.Upload
1922     * @since 6
1923     */
1924    /**
1925     * The requested form data.
1926     *
1927     * @permission ohos.permission.INTERNET
1928     * @type { Array<RequestData> }
1929     * @syscap SystemCapability.MiscServices.Upload
1930     * @crossplatform
1931     * @since 10
1932     */
1933    data: Array<RequestData>;
1934  }
1935
1936  /**
1937   * TaskState data Structure
1938   *
1939   * @interface TaskState
1940   * @permission ohos.permission.INTERNET
1941   * @syscap SystemCapability.MiscServices.Upload
1942   * @since 9
1943   * @name TaskState
1944   */
1945  /**
1946   * TaskState data Structure
1947   *
1948   * @typedef TaskState
1949   * @permission ohos.permission.INTERNET
1950   * @syscap SystemCapability.MiscServices.Upload
1951   * @crossplatform
1952   * @since 10
1953   */
1954  interface TaskState {
1955    /**
1956     * Upload file path.
1957     *
1958     * @permission ohos.permission.INTERNET
1959     * @syscap SystemCapability.MiscServices.Upload
1960     * @since 9
1961     */
1962    /**
1963     * Upload file path.
1964     *
1965     * @permission ohos.permission.INTERNET
1966     * @type { string }
1967     * @syscap SystemCapability.MiscServices.Upload
1968     * @crossplatform
1969     * @since 10
1970     */
1971    path: string;
1972    /**
1973     * Upload task return value.
1974     *
1975     * @permission ohos.permission.INTERNET
1976     * @syscap SystemCapability.MiscServices.Upload
1977     * @since 9
1978     */
1979    /**
1980     * Upload task return value.
1981     *
1982     * @permission ohos.permission.INTERNET
1983     * @type { number }
1984     * @syscap SystemCapability.MiscServices.Upload
1985     * @crossplatform
1986     * @since 10
1987     */
1988    responseCode: number;
1989    /**
1990     * Upload task information.
1991     *
1992     * @permission ohos.permission.INTERNET
1993     * @syscap SystemCapability.MiscServices.Upload
1994     * @since 9
1995     */
1996    /**
1997     * Upload task information.
1998     *
1999     * @permission ohos.permission.INTERNET
2000     * @type { string }
2001     * @syscap SystemCapability.MiscServices.Upload
2002     * @crossplatform
2003     * @since 10
2004     */
2005    message: string;
2006  }
2007
2008  /**
2009   * Upload task interface
2010   *
2011   * @interface UploadTask
2012   * @permission ohos.permission.INTERNET
2013   * @syscap SystemCapability.MiscServices.Download
2014   * @since 6
2015   */
2016  /**
2017   * Upload task interface
2018   *
2019   * @typedef UploadTask
2020   * @permission ohos.permission.INTERNET
2021   * @syscap SystemCapability.MiscServices.Download
2022   * @crossplatform
2023   * @since 10
2024   */
2025  interface UploadTask {
2026    /**
2027     * Called when the current upload session is in process.
2028     *
2029     * @permission ohos.permission.INTERNET
2030     * @param { 'progress' } type progress Indicates the upload task progress.
2031     * @param { function } callback
2032     *        The callback function for the upload progress change event
2033     *        uploadedSize The length of uploaded data, in bytes
2034     *        totalSize The length of data expected to be uploaded, in bytes.
2035     * @syscap SystemCapability.MiscServices.Upload
2036     * @since 6
2037     */
2038    /**
2039     * Called when the current upload session is in process.
2040     *
2041     * @permission ohos.permission.INTERNET
2042     * @param { 'progress' } type progress Indicates the upload task progress.
2043     * @param { function } callback
2044     *        The callback function for the upload progress change event
2045     *        uploadedSize The length of uploaded data, in bytes
2046     *        totalSize The length of data expected to be uploaded, in bytes.
2047     * @syscap SystemCapability.MiscServices.Upload
2048     * @crossplatform
2049     * @since 10
2050     */
2051    on(type: 'progress', callback: (uploadedSize: number, totalSize: number) => void): void;
2052
2053    /**
2054     * Called when the current upload session is in process.
2055     *
2056     * @permission ohos.permission.INTERNET
2057     * @param { 'progress' } type progress Indicates the upload task progress.
2058     * @param { function } [callback]
2059     *        The callback function for the upload progress change event
2060     *        uploadedSize The length of uploaded data, in bytes
2061     *        totalSize The length of data expected to be uploaded, in bytes.
2062     * @syscap SystemCapability.MiscServices.Upload
2063     * @since 6
2064     */
2065    /**
2066     * Called when the current upload session is in process.
2067     *
2068     * @permission ohos.permission.INTERNET
2069     * @param { 'progress' } type progress Indicates the upload task progress.
2070     * @param { function } [callback]
2071     *        The callback function for the upload progress change event
2072     *        uploadedSize The length of uploaded data, in bytes
2073     *        totalSize The length of data expected to be uploaded, in bytes.
2074     * @syscap SystemCapability.MiscServices.Upload
2075     * @crossplatform
2076     * @since 10
2077     */
2078    off(type: 'progress', callback?: (uploadedSize: number, totalSize: number) => void): void;
2079
2080    /**
2081     * Called when the header of the current upload session has been received.
2082     *
2083     * @permission ohos.permission.INTERNET
2084     * @param { 'headerReceive' } type headerReceive Indicates the upload task headed receive.
2085     * @param { function } callback The callback function for the HTTP Response Header event
2086     *        header HTTP Response Header returned by the developer server.
2087     * @syscap SystemCapability.MiscServices.Upload
2088     * @since 7
2089     */
2090    /**
2091     * Called when the header of the current upload session has been received.
2092     *
2093     * @permission ohos.permission.INTERNET
2094     * @param { 'headerReceive' } type headerReceive Indicates the upload task headed receive.
2095     * @param { function } callback The callback function for the HTTP Response Header event
2096     *        header HTTP Response Header returned by the developer server.
2097     * @syscap SystemCapability.MiscServices.Upload
2098     * @crossplatform
2099     * @since 10
2100     */
2101    on(type: 'headerReceive', callback: (header: object) => void): void;
2102
2103    /**
2104     * Called when the header of the current upload session has been received.
2105     *
2106     * @permission ohos.permission.INTERNET
2107     * @param { 'headerReceive' } type headerReceive Indicates the upload task headed receive.
2108     * @param { function } [callback] The callback function for the HTTP Response Header event
2109     *        header HTTP Response Header returned by the developer server.
2110     * @syscap SystemCapability.MiscServices.Upload
2111     * @since 7
2112     */
2113    /**
2114     * Called when the header of the current upload session has been received.
2115     *
2116     * @permission ohos.permission.INTERNET
2117     * @param { 'headerReceive' } type headerReceive Indicates the upload task headed receive.
2118     * @param { function } [callback] The callback function for the HTTP Response Header event
2119     *        header HTTP Response Header returned by the developer server.
2120     * @syscap SystemCapability.MiscServices.Upload
2121     * @crossplatform
2122     * @since 10
2123     */
2124    off(type: 'headerReceive', callback?: (header: object) => void): void;
2125
2126    /**
2127     * Called when the current upload session complete or fail.
2128     *
2129     * @permission ohos.permission.INTERNET
2130     * @param { 'complete' | 'fail' } type Indicates the upload session event type
2131     *        complete: upload task completed
2132     *        fail: upload task failed
2133     * @param { Callback<Array<TaskState>> } callback The callback function for the upload complete or fail change event.
2134     * @syscap SystemCapability.MiscServices.Upload
2135     * @since 9
2136     */
2137    /**
2138     * Called when the current upload session complete or fail.
2139     *
2140     * @permission ohos.permission.INTERNET
2141     * @param { 'complete' | 'fail' } type Indicates the upload session event type
2142     *        complete: upload task completed
2143     *        fail: upload task failed
2144     * @param { Callback<Array<TaskState>> } callback The callback function for the upload complete or fail change event.
2145     * @syscap SystemCapability.MiscServices.Upload
2146     * @crossplatform
2147     * @since 10
2148     */
2149    on(type: 'complete' | 'fail', callback: Callback<Array<TaskState>>): void;
2150
2151    /**
2152     * Called when the current upload session complete or fail.
2153     *
2154     * @permission ohos.permission.INTERNET
2155     * @param { 'complete' | 'fail' } type Indicates the upload session event type
2156     *        complete: upload task completed
2157     *         fail: upload task failed
2158     * @param { Callback<Array<TaskState>> } [callback]
2159     * @syscap SystemCapability.MiscServices.Upload
2160     * @since 9
2161     */
2162    /**
2163     * Called when the current upload session complete or fail.
2164     *
2165     * @permission ohos.permission.INTERNET
2166     * @param { 'complete' | 'fail' } type Indicates the upload session event type
2167     *        complete: upload task completed
2168     *         fail: upload task failed
2169     * @param { Callback<Array<TaskState>> } [callback]
2170     * @syscap SystemCapability.MiscServices.Upload
2171     * @crossplatform
2172     * @since 10
2173     */
2174    off(type: 'complete' | 'fail', callback?: Callback<Array<TaskState>>): void;
2175
2176    /**
2177     * Deletes a upload session.
2178     *
2179     * @permission ohos.permission.INTERNET
2180     * @param { AsyncCallback<boolean> } callback Indicates asynchronous invoking Result.
2181     * @syscap SystemCapability.MiscServices.Upload
2182     * @since 6
2183     * @deprecated since 9
2184     * @useinstead ohos.request.delete
2185     */
2186    remove(callback: AsyncCallback<boolean>): void;
2187
2188    /**
2189     * Deletes a upload session.
2190     *
2191     * @permission ohos.permission.INTERNET
2192     * @returns { Promise<boolean> } the promise returned by the function.
2193     * @syscap SystemCapability.MiscServices.Upload
2194     * @since 6
2195     * @deprecated since 9
2196     * @useinstead ohos.request.delete
2197     */
2198    remove(): Promise<boolean>;
2199
2200    /**
2201     * Delete the upload task
2202     *
2203     * @permission ohos.permission.INTERNET
2204     * @param { AsyncCallback<boolean> } callback
2205     * @throws { BusinessError } 201 - the permissions check fails
2206     * @throws { BusinessError } 401 - the parameters check fails
2207     * @syscap SystemCapability.MiscServices.Upload
2208     * @since 9
2209     */
2210    /**
2211     * Delete the upload task
2212     *
2213     * @permission ohos.permission.INTERNET
2214     * @param { AsyncCallback<boolean> } callback
2215     * @throws { BusinessError } 201 - the permissions check fails
2216     * @throws { BusinessError } 401 - the parameters check fails
2217     * @syscap SystemCapability.MiscServices.Upload
2218     * @crossplatform
2219     * @since 10
2220     */
2221    delete(callback: AsyncCallback<boolean>): void;
2222
2223    /**
2224     * Delete the upload task
2225     *
2226     * @permission ohos.permission.INTERNET
2227     * @returns { Promise<boolean> } the promise returned by the function.
2228     * @throws { BusinessError } 201 - the permissions check fails
2229     * @throws { BusinessError } 401 - the parameters check fails
2230     * @syscap SystemCapability.MiscServices.Upload
2231     * @since 9
2232     */
2233    /**
2234     * Delete the upload task
2235     *
2236     * @permission ohos.permission.INTERNET
2237     * @returns { Promise<boolean> } the promise returned by the function.
2238     * @throws { BusinessError } 201 - the permissions check fails
2239     * @throws { BusinessError } 401 - the parameters check fails
2240     * @syscap SystemCapability.MiscServices.Upload
2241     * @crossplatform
2242     * @since 10
2243     */
2244    delete(): Promise<boolean>;
2245  }
2246
2247  /**
2248   * The request agent api.
2249   * Supports "background" and "frontend" tasks as while.
2250   * Though "background" and "frontend" here do not the same with process's concept.
2251   * All tasks will be executed at request manager service and recorded.
2252   * Background tasks is for concurrent transfer, such as caching videos for a later play.
2253   * Frontend tasks is for instant transfer, such as submitting forms for a consumption bill.
2254   * Background tasks use notification to tell user tasks' status information.
2255   * Frontend tasks use callback to tell caller tasks' status information.
2256   * Background has some automatically restore mechanism.
2257   * Frontend tasks controlled by caller.
2258   * Uses `multipart/form-data` in client request for upload.
2259   * A `Content-Disposition: attachment; filename=<filename>` response from server leads to download.
2260   * More details, please see the architecture documents of the request subsystem.
2261   *
2262   * @namespace agent
2263   * @syscap SystemCapability.Request.FileTransferAgent
2264   * @since 10
2265   */
2266  namespace agent {
2267    /**
2268     * The action options.
2269     *
2270     * @enum { number } Action
2271     * @syscap SystemCapability.Request.FileTransferAgent
2272     * @since 10
2273     */
2274    enum Action {
2275      /**
2276       * Indicates download task.
2277       *
2278       * @syscap SystemCapability.Request.FileTransferAgent
2279       * @since 10
2280       */
2281      DOWNLOAD,
2282      /**
2283       * Indicates upload task.
2284       *
2285       * @syscap SystemCapability.Request.FileTransferAgent
2286       * @since 10
2287       */
2288      UPLOAD
2289    }
2290
2291    /**
2292     * The mode options.
2293     *
2294     * @enum { number } Mode
2295     * @syscap SystemCapability.Request.FileTransferAgent
2296     * @since 10
2297     */
2298    enum Mode {
2299      /**
2300       * Indicates background task.
2301       *
2302       * @syscap SystemCapability.Request.FileTransferAgent
2303       * @since 10
2304       */
2305      BACKGROUND,
2306      /**
2307       * Indicates foreground task.
2308       *
2309       * @syscap SystemCapability.Request.FileTransferAgent
2310       * @since 10
2311       */
2312      FOREGROUND
2313    }
2314
2315    /**
2316     * The network options.
2317     *
2318     * @enum { number } Network
2319     * @syscap SystemCapability.Request.FileTransferAgent
2320     * @since 10
2321     */
2322    enum Network {
2323      /**
2324       * Indicates no restriction on network type.
2325       *
2326       * @syscap SystemCapability.Request.FileTransferAgent
2327       * @since 10
2328       */
2329      ANY,
2330      /**
2331       * Indicates Wi-Fi only.
2332       *
2333       * @syscap SystemCapability.Request.FileTransferAgent
2334       * @since 10
2335       */
2336      WIFI,
2337      /**
2338       * Indicates cellular only.
2339       *
2340       * @syscap SystemCapability.Request.FileTransferAgent
2341       * @since 10
2342       */
2343      CELLULAR
2344    }
2345
2346    /**
2347     * The file information for a form item.
2348     *
2349     * @typedef FileSpec
2350     * @syscap SystemCapability.Request.FileTransferAgent
2351     * @since 10
2352     */
2353    interface FileSpec {
2354      /**
2355       * A relative path string, like "./xxx/yyy/zzz.html", "xxx/yyy/zzz.html", in the caller's cache directory.
2356       *
2357       * @type { string }
2358       * @syscap SystemCapability.Request.FileTransferAgent
2359       * @since 10
2360       */
2361      path: string;
2362      /**
2363       * The MIME type of the file.
2364       * The default is obtained by the suffix of the filename.
2365       *
2366       * @type { ?string }
2367       * @syscap SystemCapability.Request.FileTransferAgent
2368       * @since 10
2369       */
2370      mimeType?: string;
2371      /**
2372       * The filename, the default is obtained by path.
2373       *
2374       * @type { ?string }
2375       * @syscap SystemCapability.Request.FileTransferAgent
2376       * @since 10
2377       */
2378      filename?: string;
2379      /**
2380       * The extras for the file information.
2381       *
2382       * @type { ?object }
2383       * @syscap SystemCapability.Request.FileTransferAgent
2384       * @since 10
2385       */
2386      extras?: object;
2387    }
2388
2389    /**
2390     * The form item information for a task.
2391     *
2392     * @typedef FormItem
2393     * @syscap SystemCapability.Request.FileTransferAgent
2394     * @since 10
2395     */
2396    interface FormItem {
2397      /**
2398       * The item's name.
2399       *
2400       * @type { string }
2401       * @syscap SystemCapability.Request.FileTransferAgent
2402       * @since 10
2403       */
2404      name: string;
2405      /**
2406       * The item's value.
2407       *
2408       * @type { string | FileSpec | Array<FileSpec> }
2409       * @syscap SystemCapability.Request.FileTransferAgent
2410       * @since 10
2411       */
2412      value: string | FileSpec | Array<FileSpec>;
2413    }
2414
2415    /**
2416     * The configurations for a task.
2417     * Using a flexible configuration for clear upload and download functions.
2418     * If without emphasis, an option is for any task.
2419     *
2420     * @typedef Config
2421     * @syscap SystemCapability.Request.FileTransferAgent
2422     * @since 10
2423     */
2424    interface Config {
2425      /**
2426       * The task action, upload or download.
2427       *
2428       * @type { Action }
2429       * @syscap SystemCapability.Request.FileTransferAgent
2430       * @since 10
2431       */
2432      action: Action;
2433      /**
2434       * The Universal Resource Locator for a task.
2435       * The maximum length is 2048 characters.
2436       * Using raw `url` option, even url parameters in it.
2437       *
2438       * @type { string }
2439       * @syscap SystemCapability.Request.FileTransferAgent
2440       * @since 10
2441       */
2442      url: string;
2443      /**
2444       * The title for a task, give a meaningful title please.
2445       * The maximum length is 256 characters.
2446       * The default is the same with its action.
2447       *
2448       * @type { ?string }
2449       * @syscap SystemCapability.Request.FileTransferAgent
2450       * @since 10
2451       */
2452      title?: string;
2453      /**
2454       * The details for a task.
2455       * The maximum length is 1024 characters.
2456       * The default is empty string.
2457       *
2458       * @type { ?string }
2459       * @syscap SystemCapability.Request.FileTransferAgent
2460       * @since 10
2461       */
2462      description?: string;
2463      /**
2464       * Indicates task's mode.
2465       * The default is background.
2466       * For frontend task, it has callbacks.
2467       * For background task, it has notifications and fallback.
2468       *
2469       * @type { ?Mode }
2470       * @syscap SystemCapability.Request.FileTransferAgent
2471       * @since 10
2472       */
2473      mode?: Mode;
2474      /**
2475       * The solution choice when path already exists during download.
2476       * Currently support:
2477       * true, rewrite the existed file.
2478       * false, go to fail.
2479       *
2480       * @type { ?boolean }
2481       * @syscap SystemCapability.Request.FileTransferAgent
2482       * @since 10
2483       */
2484      overwrite?: boolean;
2485      /**
2486       * The HTTP standard method for upload or download: GET/POST/PUT.
2487       * Case insensitive.
2488       * For upload, use PUT/POST, the default is PUT.
2489       * For download, use GET/POST, the default is GET.
2490       *
2491       * @type { ?string }
2492       * @syscap SystemCapability.Request.FileTransferAgent
2493       * @since 10
2494       */
2495      method?: string;
2496      /**
2497       * The HTTP headers.
2498       * For upload request, the `Content-Type` is forced to `multipart/form-data`.
2499       * For download request, the default `Content-Type` is `application/json`.
2500       *
2501       * @type { ?object }
2502       * @syscap SystemCapability.Request.FileTransferAgent
2503       * @since 10
2504       */
2505      headers?: object;
2506      /**
2507       * The arguments, it can be any text, uses json usually.
2508       * For download, it can be raw string, the default is empty string.
2509       * For upload, it can be form items, the default is a empty form.
2510       * there must be one `FileSpec` item at least or will be a parameter error.
2511       *
2512       * @type { ?(string | Array<FormItem>) }
2513       * @syscap SystemCapability.Request.FileTransferAgent
2514       * @since 10
2515       */
2516      data?: string | Array<FormItem>;
2517      /**
2518       * The path to save the downloaded file, the default is "./".
2519       * Currently support:
2520       * 1: relative path, like "./xxx/yyy/zzz.html", "xxx/yyy/zzz.html", under caller's cache folder.
2521       * 2: uri path, like "datashare://bundle/xxx/yyy/zzz.html", the data provider must allow the caller's access.
2522       *
2523       * @type { ?string }
2524       * @default ./
2525       * @syscap SystemCapability.Request.FileTransferAgent
2526       * @since 10
2527       */
2528      saveas?: string;
2529      /**
2530       * The network.
2531       *
2532       * @type { ?Network }
2533       * @default Network.ANY
2534       * @syscap SystemCapability.Request.FileTransferAgent
2535       * @since 10
2536       */
2537      network?: Network;
2538      /**
2539       * Allows work in metered network or not.
2540       * The default is false.
2541       *
2542       * @type { ?boolean }
2543       * @default false
2544       * @syscap SystemCapability.Request.FileTransferAgent
2545       * @since 10
2546       */
2547      metered?: boolean;
2548      /**
2549       * Allows work in roaming network or not.
2550       * The default is true.
2551       *
2552       * @type { ?boolean }
2553       * @syscap SystemCapability.Request.FileTransferAgent
2554       * @since 10
2555       */
2556      roaming?: boolean;
2557      /**
2558       * Enable automatic retry or not for the background task.
2559       * The frontend task is always fast-fail.
2560       *
2561       * @type { ?boolean }
2562       * @syscap SystemCapability.Request.FileTransferAgent
2563       * @since 10
2564       */
2565      retry?: boolean;
2566      /**
2567       * Allows redirect or not.
2568       * The default is yes.
2569       *
2570       * @type { ?boolean }
2571       * @syscap SystemCapability.Request.FileTransferAgent
2572       * @since 10
2573       */
2574      redirect?: boolean;
2575      /**
2576       * The index of paths for a task.
2577       * Usually used for a continuous job.
2578       * The default is 0.
2579       *
2580       * @type { ?number }
2581       * @syscap SystemCapability.Request.FileTransferAgent
2582       * @since 10
2583       */
2584      index?: number;
2585      /**
2586       * The start point of a file.
2587       * Usually used for a continuous job.
2588       * It will set the "Range" header in download.
2589       * It will start read at the point in upload.
2590       * The default is 0.
2591       *
2592       * @type { ?number }
2593       * @syscap SystemCapability.Request.FileTransferAgent
2594       * @since 10
2595       */
2596      begins?: number;
2597      /**
2598       * The end point of a file.
2599       * Usually used for a continuous job.
2600       * It will set The "Range" header in download.
2601       * It will end read at the point in upload.
2602       * The default is -1 indicating the end of the data for upload or download.
2603       *
2604       * @type { ?number }
2605       * @syscap SystemCapability.Request.FileTransferAgent
2606       * @since 10
2607       */
2608      ends?: number;
2609      /**
2610       * The policy of the progress notification for background task.
2611       * If false: only completed or failed notification, the default.
2612       * If true, emits every progress, completed or failed notifications.
2613       *
2614       * @type { ?boolean }
2615       * @syscap SystemCapability.Request.FileTransferAgent
2616       * @since 10
2617       */
2618      gauge?: boolean;
2619      /**
2620       * Breaks when fail to fetch filesize before upload/download or not.
2621       * Uses filesize for a precise gauge.
2622       * The default is not, set size as -1 indicating the case.
2623       *
2624       * @type { ?boolean }
2625       * @syscap SystemCapability.Request.FileTransferAgent
2626       * @since 10
2627       */
2628      precise?: boolean;
2629      /**
2630       * For in-application layer isolation.
2631       * If given:
2632       *   the minimum is 8 bytes.
2633       *   the maximum is 2048 bytes.
2634       * Creates a task with token, then must provide it during normal query.
2635       * So saves the token carefully, it can not be retrieved by query.
2636       * Or leave it empty.
2637       *
2638       * @type { ?string }
2639       * @syscap SystemCapability.Request.FileTransferAgent
2640       * @since 10
2641       */
2642      token?: string;
2643      /**
2644       * The extras for the configuration.
2645       *
2646       * @type { ?object }
2647       * @syscap SystemCapability.Request.FileTransferAgent
2648       * @since 10
2649       */
2650      extras?: object;
2651    }
2652
2653    /**
2654     * Indicate the current state of the task.
2655     *
2656     * @enum { number } State
2657     * @syscap SystemCapability.Request.FileTransferAgent
2658     * @since 10
2659     */
2660    enum State {
2661      /**
2662       * Indicates a task created by `new Task(Config)`.
2663       *
2664       * @syscap SystemCapability.Request.FileTransferAgent
2665       * @since 10
2666       */
2667      INITIALIZED = 0x00,
2668      /**
2669       * Indicates a task lack of resources or conditions to run or retry.
2670       *
2671       * @syscap SystemCapability.Request.FileTransferAgent
2672       * @since 10
2673       */
2674      WAITING = 0x10,
2675      /**
2676       * Indicates a task in processing now.
2677       *
2678       * @syscap SystemCapability.Request.FileTransferAgent
2679       * @since 10
2680       */
2681      RUNNING = 0x20,
2682      /**
2683       * Indicates a task failed once at least and in processing again now.
2684       *
2685       * @syscap SystemCapability.Request.FileTransferAgent
2686       * @since 10
2687       */
2688      RETRYING = 0x21,
2689      /**
2690       * Indicates a paused task which tends to be resumed for continuous work.
2691       *
2692       * @syscap SystemCapability.Request.FileTransferAgent
2693       * @since 10
2694       */
2695      PAUSED = 0x30,
2696      /**
2697       * Indicates a stopped task which must be started again.
2698       *
2699       * @syscap SystemCapability.Request.FileTransferAgent
2700       * @since 10
2701       */
2702      STOPPED = 0x31,
2703      /**
2704       * Indicates a completed task which finish its data transfer.
2705       *
2706       * @syscap SystemCapability.Request.FileTransferAgent
2707       * @since 10
2708       */
2709      COMPLETED = 0x40,
2710      /**
2711       * Indicates a failed task which interrupted by some error.
2712       *
2713       * @syscap SystemCapability.Request.FileTransferAgent
2714       * @since 10
2715       */
2716      FAILED = 0x41,
2717      /**
2718       * Indicates a removed task which can not be processed again.
2719       *
2720       * @syscap SystemCapability.Request.FileTransferAgent
2721       * @since 10
2722       */
2723      REMOVED = 0x50
2724    }
2725
2726    /**
2727     * The progress data structure.
2728     * Upload allows multiple files per upload task.
2729     * Only one file in a download task.
2730     * So using a unified data structure for progress.
2731     * Generally:
2732     * 1: sum(sizes) is total files size of the task.
2733     * 2: float(processed)/sizes[counter] is the progress for the current processing file.
2734     * 3: float(sum(sizes[:index])+processed)/sum(sizes) is the summary progress for a task.
2735     * If fetch file size in failure, the size of the file in sizes will be set as -1.
2736     *
2737     * @typedef Progress
2738     * @syscap SystemCapability.Request.FileTransferAgent
2739     * @since 10
2740     */
2741    interface Progress {
2742      /**
2743       * The current state of the task.
2744       *
2745       * @type { State }
2746       * @readonly
2747       * @syscap SystemCapability.Request.FileTransferAgent
2748       * @since 10
2749       */
2750      readonly state: State;
2751      /**
2752       * The current processing file index in a task.
2753       *
2754       * @type { number }
2755       * @readonly
2756       * @syscap SystemCapability.Request.FileTransferAgent
2757       * @since 10
2758       */
2759      readonly index: number;
2760      /**
2761       * The processed data size for the current file in a task.
2762       *
2763       * @type { number }
2764       * @readonly
2765       * @syscap SystemCapability.Request.FileTransferAgent
2766       * @since 10
2767       */
2768      readonly processed: number;
2769      /**
2770       * The sizes of files in a task.
2771       *
2772       * @type { Array<number> }
2773       * @readonly
2774       * @syscap SystemCapability.Request.FileTransferAgent
2775       * @since 10
2776       */
2777      readonly sizes: Array<number>;
2778      /**
2779       * The extras for an interaction.
2780       * Such as headers and body of response from server.
2781       * But when the Content-Disposition header responded, the body will be into the uri of its attachment only, the body here is empty.
2782       * {"headers": {"key": v}, "body": "contents"}.
2783       *
2784       * @type { ?object }
2785       * @readonly
2786       * @syscap SystemCapability.Request.FileTransferAgent
2787       * @since 10
2788       */
2789      readonly extras?: object;
2790    }
2791
2792    /**
2793     * Indicates the reason for the failure.
2794     *
2795     * @enum { number }
2796     * @syscap SystemCapability.Request.FileTransferAgent
2797     * @since 10
2798     */
2799    enum Faults {
2800      /**
2801       * Indicates others failure.
2802       *
2803       * @syscap SystemCapability.Request.FileTransferAgent
2804       * @since 10
2805       */
2806      OTHERS = 0xFF,
2807      /**
2808       * Indicates network disconnection.
2809       *
2810       * @syscap SystemCapability.Request.FileTransferAgent
2811       * @since 10
2812       */
2813      DISCONNECTED = 0x00,
2814      /**
2815       * Indicates task timeout.
2816       *
2817       * @syscap SystemCapability.Request.FileTransferAgent
2818       * @since 10
2819       */
2820      TIMEOUT = 0x10,
2821      /**
2822       * Indicates protocol error, such as 5xx response from server.
2823       *
2824       * @syscap SystemCapability.Request.FileTransferAgent
2825       * @since 10
2826       */
2827      PROTOCOL = 0x20,
2828      /**
2829       * Indicates filesystem io error, such as open/seek/read/write/close.
2830       *
2831       * @syscap SystemCapability.Request.FileTransferAgent
2832       * @since 10
2833       */
2834      FSIO = 0x40
2835    }
2836
2837    /**
2838     * The filter data structure.
2839     * Used for search, given fields works as **LOGICAL AND**.
2840     * Invalid value may cause a parameter error.
2841     *
2842     * @typedef Filter
2843     * @syscap SystemCapability.Request.FileTransferAgent
2844     * @since 10
2845     */
2846    interface Filter {
2847      /**
2848       * Specify the package name of an application.
2849       * Only for advanced search, common search will be fixed to the caller.
2850       * A "*" means any bundle.
2851       *
2852       * @type { ?string }
2853       * @syscap SystemCapability.Request.FileTransferAgent
2854       * @systemapi Hide this for inner system use.
2855       * @since 10
2856       */
2857      bundle?: string;
2858      /**
2859       * Specify the end Unix timestamp.
2860       * The default is the moment of calling.
2861       *
2862       * @type { ?number }
2863       * @syscap SystemCapability.Request.FileTransferAgent
2864       * @since 10
2865       */
2866      before?: number;
2867      /**
2868       * Specify the start Unix timestamp.
2869       * The default is "`before` - 24 hours".
2870       *
2871       * @type { ?number }
2872       * @syscap SystemCapability.Request.FileTransferAgent
2873       * @since 10
2874       */
2875      after?: number;
2876      /**
2877       * Specify the state of tasks.
2878       * The default is any state.
2879       *
2880       * @type { ?State }
2881       * @syscap SystemCapability.Request.FileTransferAgent
2882       * @since 10
2883       */
2884      state?: State;
2885      /**
2886       * Specify the action of tasks, "upload" or "download", case insensitive.
2887       * The default is upload and download.
2888       *
2889       * @type { ?Action }
2890       * @syscap SystemCapability.Request.FileTransferAgent
2891       * @since 10
2892       */
2893      action?: Action;
2894      /**
2895       * Specify task's mode.
2896       * The default is frontend and background.
2897       *
2898       * @type { ?Mode }
2899       * @syscap SystemCapability.Request.FileTransferAgent
2900       * @since 10
2901       */
2902      mode?: Mode;
2903    }
2904
2905    /**
2906     * The task information data structure for query results.
2907     * Provides common query and advanced query, visible range of fields is different.
2908     *
2909     * @typedef TaskInfo
2910     * @syscap SystemCapability.Request.FileTransferAgent
2911     * @since 10
2912     */
2913    interface TaskInfo {
2914      /**
2915       * The UID of an application.
2916       * For system query only.
2917       *
2918       * @type { ?string }
2919       * @readonly
2920       * @syscap SystemCapability.Request.FileTransferAgent
2921       * @systemapi Hide this for inner system use.
2922       * @since 10
2923       */
2924      readonly uid?: string;
2925      /**
2926       * The bundle name.
2927       * For system query only.
2928       *
2929       * @type { ?string }
2930       * @readonly
2931       * @syscap SystemCapability.Request.FileTransferAgent
2932       * @systemapi Hide this for inner system use.
2933       * @since 10
2934       */
2935      readonly bundle?: string;
2936      /**
2937       * The path to save the downloaded file.
2938       *
2939       * @type { ?string }
2940       * @syscap SystemCapability.Request.FileTransferAgent
2941       * @since 10
2942       */
2943      readonly saveas?: string;
2944      /**
2945       * The url of a task.
2946       * For `${ show }` and `${ touch }`.
2947       * It is empty string in `${ query }`.
2948       *
2949       * @type { ?string }
2950       * @readonly
2951       * @syscap SystemCapability.Request.FileTransferAgent
2952       * @since 10
2953       */
2954      readonly url?: string;
2955      /**
2956       * The arguments.
2957       * For `${ show }` and `${ touch }`.
2958       * It is empty string in `${ query }`.
2959       *
2960       * @type { ?(string | Array<FormItem>) }
2961       * @syscap SystemCapability.Request.FileTransferAgent
2962       * @since 10
2963       */
2964      readonly data?: string | Array<FormItem>;
2965      /**
2966       * The task id.
2967       *
2968       * @type { string }
2969       * @readonly
2970       * @syscap SystemCapability.Request.FileTransferAgent
2971       * @since 10
2972       */
2973      readonly tid: string;
2974      /**
2975       * The task title.
2976       *
2977       * @type { string }
2978       * @readonly
2979       * @syscap SystemCapability.Request.FileTransferAgent
2980       * @since 10
2981       */
2982      readonly title: string;
2983      /**
2984       * The task details.
2985       *
2986       * @type { string }
2987       * @readonly
2988       * @syscap SystemCapability.Request.FileTransferAgent
2989       * @since 10
2990       */
2991      readonly description: string;
2992      /**
2993       * The task action.
2994       *
2995       * @type { Action }
2996       * @readonly
2997       * @syscap SystemCapability.Request.FileTransferAgent
2998       * @since 10
2999       */
3000      readonly action: Action;
3001      /**
3002       * Specify task mode.
3003       * The default is frontend and background.
3004       *
3005       * @type { Mode }
3006       * @syscap SystemCapability.Request.FileTransferAgent
3007       * @since 10
3008       */
3009      readonly mode: Mode;
3010      /**
3011       * The MIME type in the configuration of the task.
3012       *
3013       * @type { string }
3014       * @readonly
3015       * @syscap SystemCapability.Request.FileTransferAgent
3016       * @since 10
3017       */
3018      readonly mimeType: string;
3019      /**
3020       * An instance of `Progress` for a task.
3021       *
3022       * @type { Progress }
3023       * @readonly
3024       * @syscap SystemCapability.Request.FileTransferAgent
3025       * @since 10
3026       */
3027      readonly progress: Progress;
3028      /**
3029       * The progress notification policy of a background task.
3030       *
3031       * @type { boolean }
3032       * @readonly
3033       * @syscap SystemCapability.Request.FileTransferAgent
3034       * @since 10
3035       */
3036      readonly gauge: boolean;
3037      /**
3038       * The creating date and time of a task in Unix timestamp.
3039       * It is generated by system of current device.
3040       *
3041       * @type { number }
3042       * @readonly
3043       * @syscap SystemCapability.Request.FileTransferAgent
3044       * @since 10
3045       */
3046      readonly ctime: number;
3047      /**
3048       * The modified date and time of a task in Unix timestamp.
3049       * It is generated by system of current device.
3050       *
3051       * @type { number }
3052       * @readonly
3053       * @syscap SystemCapability.Request.FileTransferAgent
3054       * @since 10
3055       */
3056      readonly mtime: number;
3057      /**
3058       * The retry switch of a task.
3059       * Just for background, frontend always disabled.
3060       *
3061       * @type { boolean }
3062       * @readonly
3063       * @syscap SystemCapability.Request.FileTransferAgent
3064       * @since 10
3065       */
3066      readonly retry: boolean;
3067      /**
3068       * The tried times of a task.
3069       *
3070       * @type { number }
3071       * @readonly
3072       * @syscap SystemCapability.Request.FileTransferAgent
3073       * @since 10
3074       */
3075      readonly tries: number;
3076      /**
3077       * The faults case of a task.
3078       *
3079       * @type { Faults }
3080       * @readonly
3081       * @syscap SystemCapability.Request.FileTransferAgent
3082       * @since 10
3083       */
3084      readonly faults: Faults;
3085      /**
3086       * The reason of a waiting/failed/stopped/paused task.
3087       *
3088       * @type { string }
3089       * @readonly
3090       * @syscap SystemCapability.Request.FileTransferAgent
3091       * @since 10
3092       */
3093      readonly reason: string;
3094      /**
3095       * The extras of a task.
3096       * For background, the last response from server.
3097       * For frontend, nothing now.
3098       *
3099       * @type { ?object }
3100       * @readonly
3101       * @syscap SystemCapability.Request.FileTransferAgent
3102       * @since 10
3103       */
3104      readonly extras?: object;
3105    }
3106
3107    /**
3108     * The task entry.
3109     * New task' status is "initialized" and enqueue.
3110     * For background, no callbacks.
3111     * Can `start` a initialized task.
3112     * Can `pause` a waiting/running/retrying background task.
3113     * Can `resume` a paused background task.
3114     * Can `stop` a running/waiting/retrying task and dequeue it.
3115     *
3116     * @typedef Task
3117     * @syscap SystemCapability.Request.FileTransferAgent
3118     * @since 10
3119     */
3120    interface Task {
3121      /**
3122       * The task id, unique on system.
3123       * Generated automatically by system.
3124       *
3125       * @type { string }
3126       * @readonly
3127       * @syscap SystemCapability.Request.FileTransferAgent
3128       * @since 10
3129       */
3130      readonly tid: string;
3131      /**
3132       * The configurations for the task.
3133       *
3134       * @type { Config }
3135       * @syscap SystemCapability.Request.FileTransferAgent
3136       * @since 10
3137       */
3138      config: Config;
3139      /**
3140       * Enable the specified callback for a frontend task.
3141       *
3142       * @param { 'progress' } event event types.
3143       * @param { function } callback callback function with a `Progress` argument.
3144       * @throws { BusinessError } 401 - Parameter error.
3145       * @throws { BusinessError } 21900005 - task mode error.
3146       * @syscap SystemCapability.Request.FileTransferAgent
3147       * @since 10
3148       */
3149      on(event: 'progress', callback: (progress: Progress) => void): void;
3150      /**
3151       * Disable the specified callback for a frontend task.
3152       *
3153       * @param { 'progress' } event event types.
3154       * @param { function } callback callback function with a `Progress` argument.
3155       * @throws { BusinessError } 401 - Parameter error.
3156       * @throws { BusinessError } 21900005 - task mode error.
3157       * @syscap SystemCapability.Request.FileTransferAgent
3158       * @since 10
3159       */
3160      off(event: 'progress', callback?: (progress: Progress) => void): void;
3161      /**
3162       * Enable the specified callback for a frontend task.
3163       *
3164       * @param { 'completed' } event event types.
3165       * @param { function } callback callback function with a `Progress` argument.
3166       * @throws { BusinessError } 401 - Parameter error.
3167       * @throws { BusinessError } 21900005 - task mode error.
3168       * @syscap SystemCapability.Request.FileTransferAgent
3169       * @since 10
3170       */
3171      on(event: 'completed', callback: (progress: Progress) => void): void;
3172      /**
3173       * Disable the specified callback for a frontend task.
3174       *
3175       * @param { 'completed' } event event types.
3176       * @param { function } callback callback function with a `Progress` argument.
3177       * @throws { BusinessError } 401 - Parameter error.
3178       * @throws { BusinessError } 21900005 - task mode error.
3179       * @syscap SystemCapability.Request.FileTransferAgent
3180       * @since 10
3181       */
3182      off(event: 'completed', callback?: (progress: Progress) => void): void;
3183      /**
3184       * Enable the specified callback for a frontend task.
3185       *
3186       * @param { 'failed' } event event types.
3187       * @param { function } callback callback function with a `Progress` argument.
3188       * @throws { BusinessError } 401 - Parameter error.
3189       * @throws { BusinessError } 21900005 - task mode error.
3190       * @syscap SystemCapability.Request.FileTransferAgent
3191       * @since 10
3192       */
3193      on(event: 'failed', callback: (progress: Progress) => void): void;
3194      /**
3195       * Disable the specified callback for a frontend task.
3196       *
3197       * @param { 'failed' } event event types.
3198       * @param { function } callback callback function with a `Progress` argument.
3199       * @throws { BusinessError } 401 - Parameter error.
3200       * @throws { BusinessError } 21900005 - task mode error.
3201       * @syscap SystemCapability.Request.FileTransferAgent
3202       * @since 10
3203       */
3204      off(event: 'failed', callback?: (progress: Progress) => void): void;
3205      /**
3206       * Starts the task.
3207       *
3208       * @permission ohos.permission.INTERNET
3209       * @param { AsyncCallback<void> } callback callback function with a boolean argument indicating the calling result.
3210       * @throws { BusinessError } 201 - Permission denied.
3211       * @throws { BusinessError } 13400003 - task service ability error.
3212       * @throws { BusinessError } 21900007 - task state error.
3213       * @syscap SystemCapability.Request.FileTransferAgent
3214       * @since 10
3215       */
3216      start(callback: AsyncCallback<void>): void;
3217      /**
3218       * Starts the task.
3219       *
3220       * @permission ohos.permission.INTERNET
3221       * @returns { Promise<void> } the promise returned by the function.
3222       * @throws { BusinessError } 201 - Permission denied.
3223       * @throws { BusinessError } 13400003 - task service ability error.
3224       * @throws { BusinessError } 21900007 - task state error.
3225       * @syscap SystemCapability.Request.FileTransferAgent
3226       * @since 10
3227       */
3228      start(): Promise<void>;
3229      /**
3230       * Pauses the background task.
3231       *
3232       * @param { AsyncCallback<void> } callback callback function with a boolean argument indicating the calling result.
3233       * @throws { BusinessError } 13400003 - task service ability error.
3234       * @throws { BusinessError } 21900005 - task mode error.
3235       * @throws { BusinessError } 21900007 - task state error.
3236       * @syscap SystemCapability.Request.FileTransferAgent
3237       * @since 10
3238       */
3239      pause(callback: AsyncCallback<void>): void;
3240      /**
3241       * Pauses the background task.
3242       *
3243       * @returns { Promise<void> } the promise returned by the function.
3244       * @throws { BusinessError } 13400003 - task service ability error.
3245       * @throws { BusinessError } 21900005 - task mode error.
3246       * @throws { BusinessError } 21900007 - task state error.
3247       * @syscap SystemCapability.Request.FileTransferAgent
3248       * @since 10
3249       */
3250      pause(): Promise<void>;
3251      /**
3252       * Resumes the background task.
3253       *
3254       * @permission ohos.permission.INTERNET
3255       * @param { AsyncCallback<void> } callback callback function with a boolean argument indicating the calling result.
3256       * @throws { BusinessError } 201 - Permission denied.
3257       * @throws { BusinessError } 13400003 - task service ability error.
3258       * @throws { BusinessError } 21900005 - task mode error.
3259       * @throws { BusinessError } 21900007 - task state error.
3260       * @syscap SystemCapability.Request.FileTransferAgent
3261       * @since 10
3262       */
3263      resume(callback: AsyncCallback<void>): void;
3264      /**
3265       * Resumes the background task.
3266       *
3267       * @permission ohos.permission.INTERNET
3268       * @returns { Promise<void> } the promise returned by the function.
3269       * @throws { BusinessError } 201 - Permission denied.
3270       * @throws { BusinessError } 13400003 - task service ability error.
3271       * @throws { BusinessError } 21900005 - task mode error.
3272       * @throws { BusinessError } 21900007 - task state error.
3273       * @syscap SystemCapability.Request.FileTransferAgent
3274       * @since 10
3275       */
3276      resume(): Promise<void>;
3277      /**
3278       * Stops the task.
3279       *
3280       * @param { AsyncCallback<void> } callback callback function with a boolean argument indicating the calling result.
3281       * @throws { BusinessError } 13400003 - task service ability error.
3282       * @throws { BusinessError } 21900007 - task state error.
3283       * @syscap SystemCapability.Request.FileTransferAgent
3284       * @since 10
3285       */
3286      stop(callback: AsyncCallback<void>): void;
3287      /**
3288       * Stops the task.
3289       *
3290       * @returns { Promise<void> } the promise returned by the function.
3291       * @throws { BusinessError } 13400003 - task service ability error.
3292       * @throws { BusinessError } 21900007 - task state error.
3293       * @syscap SystemCapability.Request.FileTransferAgent
3294       * @since 10
3295       */
3296      stop(): Promise<void>;
3297    }
3298
3299    /**
3300     * Creates a task for upload or download and enqueue it.
3301     * Only foreground application can create the frontend task.
3302     * It can deal only one frontend task at a time.
3303     * A in processing frontend task will be forced to stop when its application had switched to background.
3304     * A new frontend task will interrupt a existed in processing frontend task.
3305     * The background task is highly recommended.
3306     *
3307     * @permission ohos.permission.INTERNET
3308     * @param { BaseContext } context context of the caller.
3309     * @param { Config } config configurations for a task.
3310     * @param { AsyncCallback<Task> } callback indicate the callback function to receive Task.
3311     * @throws { BusinessError } 201 - permission denied.
3312     * @throws { BusinessError } 401 - parameter error.
3313     * @throws { BusinessError } 13400001 - file operation error.
3314     * @throws { BusinessError } 13400003 - task service ability error.
3315     * @throws { BusinessError } 21900004 - application task queue full error.
3316     * @throws { BusinessError } 21900005 - task mode error.
3317     * @syscap SystemCapability.Request.FileTransferAgent
3318     * @since 10
3319     */
3320    function create(context: BaseContext, config: Config, callback: AsyncCallback<Task>): void;
3321
3322    /**
3323     * Creates a task for upload or download and enqueue it.
3324     * Only foreground application can create the frontend task.
3325     * It can deal only one frontend task at a time.
3326     * A in processing frontend task will be forced to stop when its application had switched to background.
3327     * A new frontend task will interrupt a existed in processing frontend task.
3328     * The background task is highly recommended.
3329     *
3330     * @permission ohos.permission.INTERNET
3331     * @param { BaseContext } context context of the caller.
3332     * @param { Config } config configurations for a task.
3333     * @returns { Promise<Task> } the promise returned by the function.
3334     * @throws { BusinessError } 201 - permission denied.
3335     * @throws { BusinessError } 401 - parameter error.
3336     * @throws { BusinessError } 13400001 - file operation error.
3337     * @throws { BusinessError } 13400003 - task service ability error.
3338     * @throws { BusinessError } 21900004 - application task queue full error.
3339     * @throws { BusinessError } 21900005 - task mode error.
3340     * @syscap SystemCapability.Request.FileTransferAgent
3341     * @since 10
3342     */
3343    function create(context: BaseContext, config: Config): Promise<Task>;
3344
3345    /**
3346     * Removes specified task belongs to the caller.
3347     * The task will be forced to stop if in processing.
3348     *
3349     * @param { string } id the task id.
3350     * @param { AsyncCallback<void> } callback callback function with a boolean argument indicating success or not.
3351     * @throws { BusinessError } 401 - parameter error.
3352     * @throws { BusinessError } 13400003 - task service ability error.
3353     * @throws { BusinessError } 21900006 - task not found error.
3354     * @syscap SystemCapability.Request.FileTransferAgent
3355     * @since 10
3356     */
3357    function remove(id: string, callback: AsyncCallback<void>): void;
3358
3359    /**
3360     * Removes specified task belongs to the caller.
3361     * The task will be forced to stop if in processing.
3362     *
3363     * @param { string } id the task id.
3364     * @returns { Promise<void> } the promise returned by the function.
3365     * @throws { BusinessError } 401 - parameter error.
3366     * @throws { BusinessError } 13400003 - task service ability error.
3367     * @throws { BusinessError } 21900006 - task not found error.
3368     * @syscap SystemCapability.Request.FileTransferAgent
3369     * @since 10
3370     */
3371    function remove(id: string): Promise<void>;
3372
3373    /**
3374     * Shows specified task details belongs to the caller.
3375     *
3376     * @param { string } id the task id.
3377     * @param { AsyncCallback<TaskInfo> } callback callback function with a `TaskInfo` argument for informations of the current task.
3378     * @throws { BusinessError } 401 - parameter error.
3379     * @throws { BusinessError } 13400003 - task service ability error.
3380     * @throws { BusinessError } 21900006 - task not found error.
3381     * @syscap SystemCapability.Request.FileTransferAgent
3382     * @since 10
3383     */
3384    function show(id: string, callback: AsyncCallback<TaskInfo>): void;
3385
3386    /**
3387     * Shows specified task details belongs to the caller.
3388     *
3389     * @param { string } id the task id.
3390     * @returns { Promise<TaskInfo> } the promise returned by the function.
3391     * @throws { BusinessError } 401 - parameter error.
3392     * @throws { BusinessError } 13400003 - task service ability error.
3393     * @throws { BusinessError } 21900006 - task not found error.
3394     * @syscap SystemCapability.Request.FileTransferAgent
3395     * @since 10
3396     */
3397    function show(id: string): Promise<TaskInfo>;
3398
3399    /**
3400     * Touches specified task with token.
3401     *
3402     * @param { string } id the task id.
3403     * @param { string } token the in-application isolation key.
3404     * @param { AsyncCallback<TaskInfo> } callback callback function with a `TaskInfo` argument for informations of the current task.
3405     * @throws { BusinessError } 401 - parameter error.
3406     * @throws { BusinessError } 13400003 - task service ability error.
3407     * @throws { BusinessError } 21900006 - task not found error.
3408     * @syscap SystemCapability.Request.FileTransferAgent
3409     * @since 10
3410     */
3411    function touch(id: string, token: string, callback: AsyncCallback<TaskInfo>): void;
3412
3413    /**
3414     * Touches specified task with token.
3415     *
3416     * @param { string } id the task id.
3417     * @param { string } token the in-application isolation key.
3418     * @returns { Promise<TaskInfo> } the promise returned by the function.
3419     * @throws { BusinessError } 401 - parameter error.
3420     * @throws { BusinessError } 13400003 - task service ability error.
3421     * @throws { BusinessError } 21900006 - task not found error.
3422     * @syscap SystemCapability.Request.FileTransferAgent
3423     * @since 10
3424     */
3425    function touch(id: string, token: string): Promise<TaskInfo>;
3426
3427    /**
3428     * Searches tasks, for system.
3429     *
3430     * @param { AsyncCallback<Array<string>> } callback callback function with a `Array<string>` argument contains task ids match filter.
3431     * @throws { BusinessError } 401 - parameter error.
3432     * @throws { BusinessError } 13400003 - task service ability error.
3433     * @syscap SystemCapability.Request.FileTransferAgent
3434     * @since 10
3435     */
3436    function search(callback: AsyncCallback<Array<string>>): void;
3437
3438    /**
3439     * Searches tasks, for system.
3440     *
3441     * @param { Filter } filter an instance of `Filter`.
3442     * @param { AsyncCallback<Array<string>> } callback callback function with a `Array<string>` argument contains task ids match filter.
3443     * @throws { BusinessError } 401 - parameter error.
3444     * @throws { BusinessError } 13400003 - task service ability error.
3445     * @syscap SystemCapability.Request.FileTransferAgent
3446     * @since 10
3447     */
3448    function search(filter: Filter, callback: AsyncCallback<Array<string>>): void;
3449
3450    /**
3451     * Searches tasks, for system.
3452     *
3453     * @param { Filter } filter an instance of `Filter`.
3454     * @returns { Promise<Array<string>> } the promise returned by the function.
3455     * @throws { BusinessError } 401 - parameter error.
3456     * @throws { BusinessError } 13400003 - task service ability error.
3457     * @syscap SystemCapability.Request.FileTransferAgent
3458     * @since 10
3459     */
3460    function search(filter?: Filter): Promise<Array<string>>;
3461
3462    /**
3463     * Queries specified task details.
3464     *
3465     * @permission ohos.permission.DOWNLOAD_SESSION_MANAGER or ohos.permission.UPLOAD_SESSION_MANAGER
3466     * @param { string } id the task id.
3467     * @param { AsyncCallback<TaskInfo> } callback callback function with a `TaskInfo` argument for informations of the current task.
3468     * @throws { BusinessError } 201 - permission denied.
3469     * @throws { BusinessError } 202 - permission verification failed, application which is not a system application uses system API.
3470     * @throws { BusinessError } 401 - parameter error.
3471     * @throws { BusinessError } 13400003 - task service ability error.
3472     * @throws { BusinessError } 21900006 - task not found error.
3473     * @syscap SystemCapability.Request.FileTransferAgent
3474     * @systemapi Hide this for inner system use.
3475     * @since 10
3476     */
3477    function query(id: string, callback: AsyncCallback<TaskInfo>): void;
3478
3479    /**
3480     * Queries specified task details.
3481     *
3482     * @permission ohos.permission.DOWNLOAD_SESSION_MANAGER or ohos.permission.UPLOAD_SESSION_MANAGER
3483     * @param { string } id the task id.
3484     * @returns { Promise<TaskInfo> } the promise returned by the function.
3485     * @throws { BusinessError } 201 - permission denied.
3486     * @throws { BusinessError } 202 - permission verification failed, application which is not a system application uses system API.
3487     * @throws { BusinessError } 401 - parameter error.
3488     * @throws { BusinessError } 13400003 - task service ability error.
3489     * @throws { BusinessError } 21900006 - task not found error.
3490     * @syscap SystemCapability.Request.FileTransferAgent
3491     * @systemapi Hide this for inner system use.
3492     * @since 10
3493     */
3494    function query(id: string): Promise<TaskInfo>;
3495  }
3496}
3497
3498export default request;
3499