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 16/** 17 * @file 18 * @kit BasicServicesKit 19 */ 20 21import { AsyncCallback } from './@ohos.base'; 22import { Callback } from './@ohos.base'; 23import BaseContext from './application/BaseContext'; 24 25/** 26 * upload and download 27 * 28 * @namespace request 29 * @permission ohos.permission.INTERNET 30 * @since 6 31 */ 32/** 33 * upload and download 34 * 35 * @namespace request 36 * @since 10 37 */ 38/** 39 * upload and download 40 * 41 * @namespace request 42 * @atomicservice 43 * @since 11 44 */ 45declare namespace request { 46 /** 47 * Error code 201 - the permissions check fails. 48 * 49 * @permission ohos.permission.INTERNET 50 * @constant 51 * @syscap SystemCapability.MiscServices.Download 52 * @since 9 53 */ 54 /** 55 * Error code 201 - the permissions check fails. 56 * 57 * @permission ohos.permission.INTERNET 58 * @constant 59 * @syscap SystemCapability.MiscServices.Download 60 * @crossplatform 61 * @since 10 62 */ 63 const EXCEPTION_PERMISSION: number; 64 /** 65 * Error code 401 - the parameters check fails. 66 * 67 * @permission ohos.permission.INTERNET 68 * @constant 69 * @syscap SystemCapability.MiscServices.Download 70 * @since 9 71 */ 72 /** 73 * Error code 401 - the parameters check fails. 74 * 75 * @permission ohos.permission.INTERNET 76 * @constant 77 * @syscap SystemCapability.MiscServices.Download 78 * @crossplatform 79 * @since 10 80 */ 81 const EXCEPTION_PARAMCHECK: number; 82 /** 83 * Error code 801 - call unsupported api. 84 * 85 * @permission ohos.permission.INTERNET 86 * @constant 87 * @syscap SystemCapability.MiscServices.Download 88 * @since 9 89 */ 90 /** 91 * Error code 801 - call unsupported api. 92 * 93 * @permission ohos.permission.INTERNET 94 * @constant 95 * @syscap SystemCapability.MiscServices.Download 96 * @crossplatform 97 * @since 10 98 */ 99 const EXCEPTION_UNSUPPORTED: number; 100 /** 101 * Error code 13400001 - file operation error. 102 * 103 * @permission ohos.permission.INTERNET 104 * @constant 105 * @syscap SystemCapability.MiscServices.Download 106 * @since 9 107 */ 108 /** 109 * Error code 13400001 - file operation error. 110 * 111 * @permission ohos.permission.INTERNET 112 * @constant 113 * @syscap SystemCapability.MiscServices.Download 114 * @crossplatform 115 * @since 10 116 */ 117 const EXCEPTION_FILEIO: number; 118 /** 119 * Error code 13400002 - bad file path. 120 * 121 * @permission ohos.permission.INTERNET 122 * @constant 123 * @syscap SystemCapability.MiscServices.Download 124 * @since 9 125 */ 126 /** 127 * Error code 13400002 - bad file path. 128 * 129 * @permission ohos.permission.INTERNET 130 * @constant 131 * @syscap SystemCapability.MiscServices.Download 132 * @crossplatform 133 * @since 10 134 */ 135 const EXCEPTION_FILEPATH: number; 136 /** 137 * Error code 13400003 - task service ability error. 138 * 139 * @permission ohos.permission.INTERNET 140 * @constant 141 * @syscap SystemCapability.MiscServices.Download 142 * @since 9 143 */ 144 /** 145 * Error code 13400003 - task service ability error. 146 * 147 * @permission ohos.permission.INTERNET 148 * @constant 149 * @syscap SystemCapability.MiscServices.Download 150 * @crossplatform 151 * @since 10 152 */ 153 const EXCEPTION_SERVICE: number; 154 /** 155 * Error code 13499999 - others error. 156 * 157 * @permission ohos.permission.INTERNET 158 * @constant 159 * @syscap SystemCapability.MiscServices.Download 160 * @since 9 161 */ 162 /** 163 * Error code 13499999 - others error. 164 * 165 * @permission ohos.permission.INTERNET 166 * @constant 167 * @syscap SystemCapability.MiscServices.Download 168 * @crossplatform 169 * @since 10 170 */ 171 const EXCEPTION_OTHERS: number; 172 173 /** 174 * Code 0x00000001 - Bit flag indicating download is allowed when using the cellular network. 175 * 176 * @permission ohos.permission.INTERNET 177 * @constant 178 * @syscap SystemCapability.MiscServices.Download 179 * @since 6 180 */ 181 /** 182 * Code 0x00000001 - Bit flag indicating download is allowed when using the cellular network. 183 * 184 * @permission ohos.permission.INTERNET 185 * @constant 186 * @syscap SystemCapability.MiscServices.Download 187 * @crossplatform 188 * @since 10 189 */ 190 const NETWORK_MOBILE: number; 191 192 /** 193 * Code 0x00010000 - Bit flag indicating download is allowed when using the WLAN. 194 * 195 * @permission ohos.permission.INTERNET 196 * @constant 197 * @syscap SystemCapability.MiscServices.Download 198 * @since 6 199 */ 200 /** 201 * Code 0x00010000 - Bit flag indicating download is allowed when using the WLAN. 202 * 203 * @permission ohos.permission.INTERNET 204 * @constant 205 * @syscap SystemCapability.MiscServices.Download 206 * @crossplatform 207 * @since 10 208 */ 209 const NETWORK_WIFI: number; 210 211 /** 212 * Error code 0 - Indicates that the download cannot be resumed for network reasons. 213 * 214 * @permission ohos.permission.INTERNET 215 * @constant 216 * @syscap SystemCapability.MiscServices.Download 217 * @since 7 218 */ 219 /** 220 * Error code 0 - Indicates that the download cannot be resumed for network reasons. 221 * 222 * @permission ohos.permission.INTERNET 223 * @constant 224 * @syscap SystemCapability.MiscServices.Download 225 * @crossplatform 226 * @since 10 227 */ 228 const ERROR_CANNOT_RESUME: number; 229 230 /** 231 * Error code 1 - Indicates that no storage device, such as an SD card, is found. 232 * 233 * @permission ohos.permission.INTERNET 234 * @constant 235 * @syscap SystemCapability.MiscServices.Download 236 * @since 7 237 */ 238 /** 239 * Error code 1 - Indicates that no storage device, such as an SD card, is found. 240 * 241 * @permission ohos.permission.INTERNET 242 * @constant 243 * @syscap SystemCapability.MiscServices.Download 244 * @crossplatform 245 * @since 10 246 */ 247 const ERROR_DEVICE_NOT_FOUND: number; 248 249 /** 250 * Error code 2 - Indicates that files to be downloaded already exist, and that the download session cannot overwrite the existing files. 251 * 252 * @permission ohos.permission.INTERNET 253 * @constant 254 * @syscap SystemCapability.MiscServices.Download 255 * @since 7 256 */ 257 /** 258 * Error code 2 - Indicates that files to be downloaded already exist, and that the download session cannot overwrite the existing files. 259 * 260 * @permission ohos.permission.INTERNET 261 * @constant 262 * @syscap SystemCapability.MiscServices.Download 263 * @crossplatform 264 * @since 10 265 */ 266 const ERROR_FILE_ALREADY_EXISTS: number; 267 268 /** 269 * Error code 3 - Indicates that a file operation fails. 270 * 271 * @permission ohos.permission.INTERNET 272 * @constant 273 * @syscap SystemCapability.MiscServices.Download 274 * @since 7 275 */ 276 /** 277 * Error code 3 - Indicates that a file operation fails. 278 * 279 * @permission ohos.permission.INTERNET 280 * @constant 281 * @syscap SystemCapability.MiscServices.Download 282 * @crossplatform 283 * @since 10 284 */ 285 const ERROR_FILE_ERROR: number; 286 287 /** 288 * Error code 4 - Indicates that the HTTP transmission fails. 289 * 290 * @permission ohos.permission.INTERNET 291 * @constant 292 * @syscap SystemCapability.MiscServices.Download 293 * @since 7 294 */ 295 /** 296 * Error code 4 - Indicates that the HTTP transmission fails. 297 * 298 * @permission ohos.permission.INTERNET 299 * @constant 300 * @syscap SystemCapability.MiscServices.Download 301 * @crossplatform 302 * @since 10 303 */ 304 const ERROR_HTTP_DATA_ERROR: number; 305 306 /** 307 * Error code 5 - Indicates insufficient storage space. 308 * 309 * @permission ohos.permission.INTERNET 310 * @constant 311 * @syscap SystemCapability.MiscServices.Download 312 * @since 7 313 */ 314 /** 315 * Error code 5 - Indicates insufficient storage space. 316 * 317 * @permission ohos.permission.INTERNET 318 * @constant 319 * @syscap SystemCapability.MiscServices.Download 320 * @crossplatform 321 * @since 10 322 */ 323 const ERROR_INSUFFICIENT_SPACE: number; 324 325 /** 326 * Error code 6 - Indicates an error caused by too many network redirections. 327 * 328 * @permission ohos.permission.INTERNET 329 * @constant 330 * @syscap SystemCapability.MiscServices.Download 331 * @since 7 332 */ 333 /** 334 * Error code 6 - Indicates an error caused by too many network redirections. 335 * 336 * @permission ohos.permission.INTERNET 337 * @constant 338 * @syscap SystemCapability.MiscServices.Download 339 * @crossplatform 340 * @since 10 341 */ 342 const ERROR_TOO_MANY_REDIRECTS: number; 343 344 /** 345 * Error code 7 - Indicates an HTTP code that cannot be identified. 346 * 347 * @permission ohos.permission.INTERNET 348 * @constant 349 * @syscap SystemCapability.MiscServices.Download 350 * @since 7 351 */ 352 /** 353 * Error code 7 - Indicates an HTTP code that cannot be identified. 354 * 355 * @permission ohos.permission.INTERNET 356 * @constant 357 * @syscap SystemCapability.MiscServices.Download 358 * @crossplatform 359 * @since 10 360 */ 361 const ERROR_UNHANDLED_HTTP_CODE: number; 362 363 /** 364 * Error code 8 - Indicates an undefined error. 365 * 366 * @permission ohos.permission.INTERNET 367 * @constant 368 * @syscap SystemCapability.MiscServices.Download 369 * @since 7 370 */ 371 /** 372 * Error code 8 - Indicates an undefined error. 373 * 374 * @permission ohos.permission.INTERNET 375 * @constant 376 * @syscap SystemCapability.MiscServices.Download 377 * @crossplatform 378 * @since 10 379 */ 380 const ERROR_UNKNOWN: number; 381 382 /** 383 * Error code 9 - Indicates network offline. 384 * 385 * @permission ohos.permission.INTERNET 386 * @constant 387 * @syscap SystemCapability.MiscServices.Download 388 * @since 9 389 */ 390 /** 391 * Error code 9 - Indicates network offline. 392 * 393 * @permission ohos.permission.INTERNET 394 * @constant 395 * @syscap SystemCapability.MiscServices.Download 396 * @crossplatform 397 * @since 10 398 */ 399 const ERROR_OFFLINE: number; 400 401 /** 402 * Error code 10 - Indicates network type configuration error. 403 * 404 * @permission ohos.permission.INTERNET 405 * @constant 406 * @syscap SystemCapability.MiscServices.Download 407 * @since 9 408 */ 409 /** 410 * Error code 10 - Indicates network type configuration error. 411 * 412 * @permission ohos.permission.INTERNET 413 * @constant 414 * @syscap SystemCapability.MiscServices.Download 415 * @crossplatform 416 * @since 10 417 */ 418 const ERROR_UNSUPPORTED_NETWORK_TYPE: number; 419 420 /** 421 * Paused code 0 - Indicates that the download is paused and waiting for a WLAN connection, 422 * because the file size exceeds the maximum allowed for a session using the cellular network. 423 * 424 * @permission ohos.permission.INTERNET 425 * @constant 426 * @syscap SystemCapability.MiscServices.Download 427 * @since 7 428 */ 429 /** 430 * Paused code 0 - Indicates that the download is paused and waiting for a WLAN connection, 431 * because the file size exceeds the maximum allowed for a session using the cellular network. 432 * 433 * @permission ohos.permission.INTERNET 434 * @constant 435 * @syscap SystemCapability.MiscServices.Download 436 * @crossplatform 437 * @since 10 438 */ 439 const PAUSED_QUEUED_FOR_WIFI: number; 440 441 /** 442 * Paused code 1 - Indicates that the download is paused due to a network problem, for example, network disconnection. 443 * 444 * @permission ohos.permission.INTERNET 445 * @constant 446 * @syscap SystemCapability.MiscServices.Download 447 * @since 7 448 */ 449 /** 450 * Paused code 1 - Indicates that the download is paused due to a network problem, for example, network disconnection. 451 * 452 * @permission ohos.permission.INTERNET 453 * @constant 454 * @syscap SystemCapability.MiscServices.Download 455 * @crossplatform 456 * @since 10 457 */ 458 const PAUSED_WAITING_FOR_NETWORK: number; 459 460 /** 461 * Paused code 2 - Indicates that a network error occurs, and the download session will be retried. 462 * 463 * @permission ohos.permission.INTERNET 464 * @constant 465 * @syscap SystemCapability.MiscServices.Download 466 * @since 7 467 */ 468 /** 469 * Paused code 2 - Indicates that a network error occurs, and the download session will be retried. 470 * 471 * @permission ohos.permission.INTERNET 472 * @constant 473 * @syscap SystemCapability.MiscServices.Download 474 * @crossplatform 475 * @since 10 476 */ 477 const PAUSED_WAITING_TO_RETRY: number; 478 479 /** 480 * Paused code 3 - Indicates that the download is paused due to the user. 481 * 482 * @permission ohos.permission.INTERNET 483 * @constant 484 * @syscap SystemCapability.MiscServices.Download 485 * @since 9 486 */ 487 /** 488 * Paused code 3 - Indicates that the download is paused due to the user. 489 * 490 * @permission ohos.permission.INTERNET 491 * @constant 492 * @syscap SystemCapability.MiscServices.Download 493 * @crossplatform 494 * @since 10 495 */ 496 const PAUSED_BY_USER: number; 497 498 /** 499 * Paused code 4 - Indicates that the download is paused for some reasons. 500 * 501 * @permission ohos.permission.INTERNET 502 * @constant 503 * @syscap SystemCapability.MiscServices.Download 504 * @since 7 505 */ 506 /** 507 * Paused code 4 - Indicates that the download is paused for some reasons. 508 * 509 * @permission ohos.permission.INTERNET 510 * @constant 511 * @syscap SystemCapability.MiscServices.Download 512 * @crossplatform 513 * @since 10 514 */ 515 const PAUSED_UNKNOWN: number; 516 517 /** 518 * Session status code 0 - Indicates that the download session is completed. 519 * 520 * @permission ohos.permission.INTERNET 521 * @constant 522 * @syscap SystemCapability.MiscServices.Download 523 * @since 7 524 */ 525 /** 526 * Session status code 0 - Indicates that the download session is completed. 527 * 528 * @permission ohos.permission.INTERNET 529 * @constant 530 * @syscap SystemCapability.MiscServices.Download 531 * @crossplatform 532 * @since 10 533 */ 534 const SESSION_SUCCESSFUL: number; 535 536 /** 537 * Session status code 1 - Indicates that the download session is in progress. 538 * 539 * @permission ohos.permission.INTERNET 540 * @constant 541 * @syscap SystemCapability.MiscServices.Download 542 * @since 7 543 */ 544 /** 545 * Session status code 1 - Indicates that the download session is in progress. 546 * 547 * @permission ohos.permission.INTERNET 548 * @constant 549 * @syscap SystemCapability.MiscServices.Download 550 * @crossplatform 551 * @since 10 552 */ 553 const SESSION_RUNNING: number; 554 555 /** 556 * Session status code 2 - Indicates that the download session is being scheduled. 557 * 558 * @permission ohos.permission.INTERNET 559 * @constant 560 * @syscap SystemCapability.MiscServices.Download 561 * @since 7 562 */ 563 /** 564 * Session status code 2 - Indicates that the download session is being scheduled. 565 * 566 * @permission ohos.permission.INTERNET 567 * @constant 568 * @syscap SystemCapability.MiscServices.Download 569 * @crossplatform 570 * @since 10 571 */ 572 const SESSION_PENDING: number; 573 574 /** 575 * Session status code 3 - Indicates that the download session has been paused. 576 * 577 * @permission ohos.permission.INTERNET 578 * @constant 579 * @syscap SystemCapability.MiscServices.Download 580 * @since 7 581 */ 582 /** 583 * Session status code 3 - Indicates that the download session has been paused. 584 * 585 * @permission ohos.permission.INTERNET 586 * @constant 587 * @syscap SystemCapability.MiscServices.Download 588 * @crossplatform 589 * @since 10 590 */ 591 const SESSION_PAUSED: number; 592 593 /** 594 * Session status code 4 - Indicates that the download session has failed and will not be retried. 595 * 596 * @permission ohos.permission.INTERNET 597 * @constant 598 * @syscap SystemCapability.MiscServices.Download 599 * @since 7 600 */ 601 /** 602 * Session status code 4 - Indicates that the download session has failed and will not be retried. 603 * 604 * @permission ohos.permission.INTERNET 605 * @constant 606 * @syscap SystemCapability.MiscServices.Download 607 * @crossplatform 608 * @since 10 609 */ 610 const SESSION_FAILED: number; 611 612 /** 613 * Starts a download task. 614 * 615 * @permission ohos.permission.INTERNET 616 * @param { DownloadConfig } config Download config 617 * @param { AsyncCallback<DownloadTask> } callback Indicate the callback function to receive DownloadTask. 618 * @syscap SystemCapability.MiscServices.Download 619 * @FAModelOnly 620 * @since 6 621 * @deprecated since 9 622 * @useinstead ohos.request.downloadFile 623 */ 624 function download(config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void; 625 626 /** 627 * Starts a download task. 628 * 629 * @permission ohos.permission.INTERNET 630 * @param { BaseContext } context Indicates the application BaseContext. 631 * @param { DownloadConfig } config Download config 632 * @param { AsyncCallback<DownloadTask> } callback Indicate the callback function to receive DownloadTask. 633 * @throws { BusinessError } 201 - the permissions check fails 634 * @throws { BusinessError } 401 - the parameters check fails 635 * @throws { BusinessError } 13400001 - file operation error 636 * @throws { BusinessError } 13400002 - bad file path 637 * @throws { BusinessError } 13400003 - task service ability error 638 * @syscap SystemCapability.MiscServices.Download 639 * @since 9 640 */ 641 /** 642 * Starts a download task. 643 * 644 * @permission ohos.permission.INTERNET 645 * @param { BaseContext } context Indicates the application BaseContext. 646 * @param { DownloadConfig } config Download config 647 * @param { AsyncCallback<DownloadTask> } callback Indicate the callback function to receive DownloadTask. 648 * @throws { BusinessError } 201 - the permissions check fails 649 * @throws { BusinessError } 401 - the parameters check fails 650 * @throws { BusinessError } 13400001 - file operation error 651 * @throws { BusinessError } 13400002 - bad file path 652 * @throws { BusinessError } 13400003 - task service ability error 653 * @syscap SystemCapability.MiscServices.Download 654 * @crossplatform 655 * @since 10 656 */ 657 function downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallback<DownloadTask>): void; 658 659 /** 660 * Starts a download task. 661 * 662 * @permission ohos.permission.INTERNET 663 * @param { DownloadConfig } config Download config 664 * @returns { Promise<DownloadTask> } the promise returned by the function. 665 * @syscap SystemCapability.MiscServices.Download 666 * @FAModelOnly 667 * @since 6 668 * @deprecated since 9 669 * @useinstead ohos.request.downloadFile 670 */ 671 function download(config: DownloadConfig): Promise<DownloadTask>; 672 673 /** 674 * Starts a download task. 675 * 676 * @permission ohos.permission.INTERNET 677 * @param { BaseContext } context Indicates the application BaseContext. 678 * @param { DownloadConfig } config Download config 679 * @returns { Promise<DownloadTask> } the promise returned by the function. 680 * @throws { BusinessError } 201 - the permissions check fails 681 * @throws { BusinessError } 401 - the parameters check fails 682 * @throws { BusinessError } 13400001 - file operation error 683 * @throws { BusinessError } 13400002 - bad file path 684 * @throws { BusinessError } 13400003 - task service ability error 685 * @syscap SystemCapability.MiscServices.Download 686 * @since 9 687 */ 688 /** 689 * Starts a download task. 690 * 691 * @permission ohos.permission.INTERNET 692 * @param { BaseContext } context Indicates the application BaseContext. 693 * @param { DownloadConfig } config Download config 694 * @returns { Promise<DownloadTask> } the promise returned by the function. 695 * @throws { BusinessError } 201 - the permissions check fails 696 * @throws { BusinessError } 401 - the parameters check fails 697 * @throws { BusinessError } 13400001 - file operation error 698 * @throws { BusinessError } 13400002 - bad file path 699 * @throws { BusinessError } 13400003 - task service ability error 700 * @syscap SystemCapability.MiscServices.Download 701 * @crossplatform 702 * @since 10 703 */ 704 function downloadFile(context: BaseContext, config: DownloadConfig): Promise<DownloadTask>; 705 706 /** 707 * Starts a upload task. 708 * 709 * @permission ohos.permission.INTERNET 710 * @param { UploadConfig } config Upload config 711 * @param { AsyncCallback<UploadTask> } callback Indicate the callback function to receive UploadTask. 712 * @syscap SystemCapability.MiscServices.Upload 713 * @FAModelOnly 714 * @since 6 715 * @deprecated since 9 716 * @useinstead ohos.request.uploadFile 717 */ 718 function upload(config: UploadConfig, callback: AsyncCallback<UploadTask>): void; 719 720 /** 721 * Starts a upload task. 722 * 723 * @permission ohos.permission.INTERNET 724 * @param { BaseContext } context Indicates the application BaseContext. 725 * @param { UploadConfig } config Upload config 726 * @param { AsyncCallback<UploadTask> } callback Indicate the callback function to receive UploadTask. 727 * @throws { BusinessError } 201 - the permissions check fails 728 * @throws { BusinessError } 401 - the parameters check fails 729 * @throws { BusinessError } 13400002 - bad file path 730 * @syscap SystemCapability.MiscServices.Upload 731 * @since 9 732 */ 733 /** 734 * Starts a upload task. 735 * 736 * @permission ohos.permission.INTERNET 737 * @param { BaseContext } context Indicates the application BaseContext. 738 * @param { UploadConfig } config Upload config 739 * @param { AsyncCallback<UploadTask> } callback Indicate the callback function to receive UploadTask. 740 * @throws { BusinessError } 201 - the permissions check fails 741 * @throws { BusinessError } 401 - the parameters check fails 742 * @throws { BusinessError } 13400002 - bad file path 743 * @syscap SystemCapability.MiscServices.Upload 744 * @crossplatform 745 * @since 10 746 */ 747 function uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback<UploadTask>): void; 748 749 /** 750 * Starts a upload task. 751 * 752 * @permission ohos.permission.INTERNET 753 * @param { UploadConfig } config Upload config 754 * @returns { Promise<UploadTask> } the promise returned by the function. 755 * @syscap SystemCapability.MiscServices.Upload 756 * @FAModelOnly 757 * @since 6 758 * @deprecated since 9 759 * @useinstead ohos.request.uploadFile 760 */ 761 function upload(config: UploadConfig): Promise<UploadTask>; 762 763 /** 764 * Starts a upload task. 765 * 766 * @permission ohos.permission.INTERNET 767 * @param { BaseContext } context Indicates the application BaseContext. 768 * @param { UploadConfig } config Upload config 769 * @returns { Promise<UploadTask> } the promise returned by the function. 770 * @throws { BusinessError } 201 - the permissions check fails 771 * @throws { BusinessError } 401 - the parameters check fails 772 * @throws { BusinessError } 13400002 - bad file path 773 * @syscap SystemCapability.MiscServices.Upload 774 * @since 9 775 */ 776 /** 777 * Starts a upload task. 778 * 779 * @permission ohos.permission.INTERNET 780 * @param { BaseContext } context Indicates the application BaseContext. 781 * @param { UploadConfig } config Upload config 782 * @returns { Promise<UploadTask> } the promise returned by the function. 783 * @throws { BusinessError } 201 - the permissions check fails 784 * @throws { BusinessError } 401 - the parameters check fails 785 * @throws { BusinessError } 13400002 - bad file path 786 * @syscap SystemCapability.MiscServices.Upload 787 * @crossplatform 788 * @since 10 789 */ 790 function uploadFile(context: BaseContext, config: UploadConfig): Promise<UploadTask>; 791 792 /** 793 * DownloadConfig data Structure 794 * 795 * @interface DownloadConfig 796 * @permission ohos.permission.INTERNET 797 * @syscap SystemCapability.MiscServices.Download 798 * @since 6 799 * @name DownloadConfig 800 */ 801 /** 802 * DownloadConfig data Structure 803 * 804 * @typedef DownloadConfig 805 * @permission ohos.permission.INTERNET 806 * @syscap SystemCapability.MiscServices.Download 807 * @crossplatform 808 * @since 10 809 * @name DownloadConfig 810 */ 811 interface DownloadConfig { 812 /** 813 * Resource address. 814 * 815 * @permission ohos.permission.INTERNET 816 * @syscap SystemCapability.MiscServices.Download 817 * @since 6 818 */ 819 /** 820 * Resource address. 821 * 822 * @permission ohos.permission.INTERNET 823 * @type { string } 824 * @syscap SystemCapability.MiscServices.Download 825 * @crossplatform 826 * @since 10 827 */ 828 url: string; 829 /** 830 * Adds an HTTP or HTTPS header to be included with the download request. 831 * 832 * @permission ohos.permission.INTERNET 833 * @syscap SystemCapability.MiscServices.Download 834 * @since 6 835 */ 836 /** 837 * Adds an HTTP or HTTPS header to be included with the download request. 838 * 839 * @permission ohos.permission.INTERNET 840 * @type { ?Object } 841 * @syscap SystemCapability.MiscServices.Download 842 * @crossplatform 843 * @since 10 844 */ 845 header?: Object; 846 /** 847 * Allows download under a metered connection. 848 * 849 * @permission ohos.permission.INTERNET 850 * @syscap SystemCapability.MiscServices.Download 851 * @since 6 852 */ 853 /** 854 * Allows download under a metered connection. 855 * 856 * @permission ohos.permission.INTERNET 857 * @type { ?boolean } 858 * @syscap SystemCapability.MiscServices.Download 859 * @crossplatform 860 * @since 10 861 */ 862 enableMetered?: boolean; 863 /** 864 * Allows download in a roaming network. 865 * 866 * @permission ohos.permission.INTERNET 867 * @syscap SystemCapability.MiscServices.Download 868 * @since 6 869 */ 870 /** 871 * Allows download in a roaming network. 872 * 873 * @permission ohos.permission.INTERNET 874 * @type { ?boolean } 875 * @syscap SystemCapability.MiscServices.Download 876 * @crossplatform 877 * @since 10 878 */ 879 enableRoaming?: boolean; 880 /** 881 * Sets the description of a download session. 882 * 883 * @permission ohos.permission.INTERNET 884 * @syscap SystemCapability.MiscServices.Download 885 * @since 6 886 */ 887 /** 888 * Sets the description of a download session. 889 * 890 * @permission ohos.permission.INTERNET 891 * @type { ?string } 892 * @syscap SystemCapability.MiscServices.Download 893 * @crossplatform 894 * @since 10 895 */ 896 description?: string; 897 /** 898 * Sets the network type allowed for download. 899 * 900 * @permission ohos.permission.INTERNET 901 * @syscap SystemCapability.MiscServices.Download 902 * @since 6 903 */ 904 /** 905 * Sets the network type allowed for download. 906 * 907 * @permission ohos.permission.INTERNET 908 * @type { ?number } 909 * @syscap SystemCapability.MiscServices.Download 910 * @crossplatform 911 * @since 10 912 */ 913 networkType?: number; 914 /** 915 * Sets the path for downloads. 916 * 917 * @permission ohos.permission.INTERNET 918 * @syscap SystemCapability.MiscServices.Download 919 * @since 7 920 */ 921 /** 922 * Sets the path for downloads. 923 * 924 * @permission ohos.permission.INTERNET 925 * @type { ?string } 926 * @syscap SystemCapability.MiscServices.Download 927 * @crossplatform 928 * @since 10 929 */ 930 filePath?: string; 931 /** 932 * Sets a download session title. 933 * 934 * @permission ohos.permission.INTERNET 935 * @syscap SystemCapability.MiscServices.Download 936 * @since 6 937 */ 938 /** 939 * Sets a download session title. 940 * 941 * @permission ohos.permission.INTERNET 942 * @type { ?string } 943 * @syscap SystemCapability.MiscServices.Download 944 * @crossplatform 945 * @since 10 946 */ 947 title?: string; 948 /** 949 * Allow download background task notifications. 950 * 951 * @permission ohos.permission.INTERNET 952 * @syscap SystemCapability.MiscServices.Download 953 * @since 9 954 */ 955 /** 956 * Allow download background task notifications. 957 * 958 * @permission ohos.permission.INTERNET 959 * @type { ?boolean } 960 * @syscap SystemCapability.MiscServices.Download 961 * @crossplatform 962 * @since 10 963 */ 964 background?: boolean; 965 } 966 967 /** 968 * DownloadInfo data Structure 969 * 970 * @interface DownloadInfo 971 * @permission ohos.permission.INTERNET 972 * @syscap SystemCapability.MiscServices.Download 973 * @since 7 974 * @name DownloadInfo 975 */ 976 /** 977 * DownloadInfo data Structure 978 * 979 * @typedef DownloadInfo 980 * @permission ohos.permission.INTERNET 981 * @syscap SystemCapability.MiscServices.Download 982 * @crossplatform 983 * @since 10 984 */ 985 interface DownloadInfo { 986 /** 987 * the description of a file to be downloaded. 988 * 989 * @permission ohos.permission.INTERNET 990 * @syscap SystemCapability.MiscServices.Download 991 * @since 7 992 */ 993 /** 994 * the description of a file to be downloaded. 995 * 996 * @permission ohos.permission.INTERNET 997 * @type { string } 998 * @syscap SystemCapability.MiscServices.Download 999 * @crossplatform 1000 * @since 10 1001 */ 1002 description: string; 1003 /** 1004 * the real-time downloads size (in bytes). 1005 * 1006 * @permission ohos.permission.INTERNET 1007 * @syscap SystemCapability.MiscServices.Download 1008 * @since 7 1009 */ 1010 /** 1011 * the real-time downloads size (in bytes). 1012 * 1013 * @permission ohos.permission.INTERNET 1014 * @type { number } 1015 * @syscap SystemCapability.MiscServices.Download 1016 * @crossplatform 1017 * @since 10 1018 */ 1019 downloadedBytes: number; 1020 /** 1021 * the ID of a file to be downloaded. 1022 * 1023 * @permission ohos.permission.INTERNET 1024 * @syscap SystemCapability.MiscServices.Download 1025 * @since 7 1026 */ 1027 /** 1028 * the ID of a file to be downloaded. 1029 * 1030 * @permission ohos.permission.INTERNET 1031 * @type { number } 1032 * @syscap SystemCapability.MiscServices.Download 1033 * @crossplatform 1034 * @since 10 1035 */ 1036 downloadId: number; 1037 /** 1038 * a download failure cause, which can be any DownloadSession.ERROR_* constant. 1039 * 1040 * @permission ohos.permission.INTERNET 1041 * @syscap SystemCapability.MiscServices.Download 1042 * @since 7 1043 */ 1044 /** 1045 * a download failure cause, which can be any DownloadSession.ERROR_* constant. 1046 * 1047 * @permission ohos.permission.INTERNET 1048 * @type { number } 1049 * @syscap SystemCapability.MiscServices.Download 1050 * @crossplatform 1051 * @since 10 1052 */ 1053 failedReason: number; 1054 /** 1055 * the name of a file to be downloaded. 1056 * 1057 * @permission ohos.permission.INTERNET 1058 * @syscap SystemCapability.MiscServices.Download 1059 * @since 7 1060 */ 1061 /** 1062 * the name of a file to be downloaded. 1063 * 1064 * @permission ohos.permission.INTERNET 1065 * @type { string } 1066 * @syscap SystemCapability.MiscServices.Download 1067 * @crossplatform 1068 * @since 10 1069 */ 1070 fileName: string; 1071 /** 1072 * the URI of a stored file. 1073 * 1074 * @permission ohos.permission.INTERNET 1075 * @syscap SystemCapability.MiscServices.Download 1076 * @since 7 1077 */ 1078 /** 1079 * the URI of a stored file. 1080 * 1081 * @permission ohos.permission.INTERNET 1082 * @type { string } 1083 * @syscap SystemCapability.MiscServices.Download 1084 * @crossplatform 1085 * @since 10 1086 */ 1087 filePath: string; 1088 /** 1089 * the reason why a session is paused, which can be any DownloadSession.PAUSED_* constant. 1090 * 1091 * @permission ohos.permission.INTERNET 1092 * @syscap SystemCapability.MiscServices.Download 1093 * @since 7 1094 */ 1095 /** 1096 * the reason why a session is paused, which can be any DownloadSession.PAUSED_* constant. 1097 * 1098 * @permission ohos.permission.INTERNET 1099 * @type { number } 1100 * @syscap SystemCapability.MiscServices.Download 1101 * @crossplatform 1102 * @since 10 1103 */ 1104 pausedReason: number; 1105 /** 1106 * the download status code, which can be any DownloadSession.SESSION_* constant. 1107 * 1108 * @permission ohos.permission.INTERNET 1109 * @syscap SystemCapability.MiscServices.Download 1110 * @since 7 1111 */ 1112 /** 1113 * the download status code, which can be any DownloadSession.SESSION_* constant. 1114 * 1115 * @permission ohos.permission.INTERNET 1116 * @type { number } 1117 * @syscap SystemCapability.MiscServices.Download 1118 * @crossplatform 1119 * @since 10 1120 */ 1121 status: number; 1122 /** 1123 * the URI of files to be downloaded. 1124 * 1125 * @permission ohos.permission.INTERNET 1126 * @syscap SystemCapability.MiscServices.Download 1127 * @since 7 1128 */ 1129 /** 1130 * the URI of files to be downloaded. 1131 * 1132 * @permission ohos.permission.INTERNET 1133 * @type { string } 1134 * @syscap SystemCapability.MiscServices.Download 1135 * @crossplatform 1136 * @since 10 1137 */ 1138 targetURI: string; 1139 /** 1140 * the title of a file to be downloaded. 1141 * 1142 * @permission ohos.permission.INTERNET 1143 * @syscap SystemCapability.MiscServices.Download 1144 * @since 7 1145 */ 1146 /** 1147 * the title of a file to be downloaded. 1148 * 1149 * @permission ohos.permission.INTERNET 1150 * @type { string } 1151 * @syscap SystemCapability.MiscServices.Download 1152 * @crossplatform 1153 * @since 10 1154 */ 1155 downloadTitle: string; 1156 /** 1157 * the total size of files to be downloaded (in bytes). 1158 * 1159 * @permission ohos.permission.INTERNET 1160 * @syscap SystemCapability.MiscServices.Download 1161 * @since 7 1162 */ 1163 /** 1164 * the total size of files to be downloaded (in bytes). 1165 * 1166 * @permission ohos.permission.INTERNET 1167 * @type { number } 1168 * @syscap SystemCapability.MiscServices.Download 1169 * @crossplatform 1170 * @since 10 1171 */ 1172 downloadTotalBytes: number; 1173 } 1174 1175 /** 1176 * Download task interface 1177 * 1178 * @interface DownloadTask 1179 * @permission ohos.permission.INTERNET 1180 * @syscap SystemCapability.MiscServices.Download 1181 * @since 6 1182 */ 1183 /** 1184 * Download task interface 1185 * 1186 * @typedef DownloadTask 1187 * @permission ohos.permission.INTERNET 1188 * @syscap SystemCapability.MiscServices.Download 1189 * @crossplatform 1190 * @since 10 1191 */ 1192 interface DownloadTask { 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 * @since 6 1204 */ 1205 /** 1206 * Called when the current download session is in process. 1207 * 1208 * @permission ohos.permission.INTERNET 1209 * @param { 'progress' } type progress Indicates the download task progress. 1210 * @param { function } callback 1211 * The callback function for the download progress change event 1212 * receivedSize the length of downloaded data, in bytes 1213 * totalSize he length of data expected to be downloaded, in bytes. 1214 * @syscap SystemCapability.MiscServices.Download 1215 * @crossplatform 1216 * @since 10 1217 */ 1218 on(type: 'progress', callback: (receivedSize: number, totalSize: number) => void): void; 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 * @since 6 1231 */ 1232 /** 1233 * Called when the current download session is in process. 1234 * 1235 * @permission ohos.permission.INTERNET 1236 * @param { 'progress' } type progress Indicates the download task progress. 1237 * @param { function } [callback] 1238 * The callback function for the download progress change event 1239 * receivedSize the length of downloaded data, in bytes 1240 * totalSize he length of data expected to be downloaded, in bytes. 1241 * @syscap SystemCapability.MiscServices.Download 1242 * @crossplatform 1243 * @since 10 1244 */ 1245 off(type: 'progress', callback?: (receivedSize: number, totalSize: number) => void): void; 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 * @since 7 1258 */ 1259 /** 1260 * Called when the current download session complete pause or remove. 1261 * 1262 * @permission ohos.permission.INTERNET 1263 * @param { 'complete' | 'pause' | 'remove' } type Indicates the download session event type 1264 * complete: download task completed, 1265 * pause: download task stopped, 1266 * remove: download task deleted. 1267 * @param { function } callback The callback function for the download complete pause or remove change event. 1268 * @syscap SystemCapability.MiscServices.Download 1269 * @crossplatform 1270 * @since 10 1271 */ 1272 on(type: 'complete' | 'pause' | 'remove', callback: () => void): void; 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 * @since 7 1285 */ 1286 /** 1287 * Called when the current download session complete pause or remove. 1288 * 1289 * @permission ohos.permission.INTERNET 1290 * @param { 'complete' | 'pause' | 'remove' } type Indicates the download session event type 1291 * complete: download task completed, 1292 * pause: download task stopped, 1293 * remove: download task deleted. 1294 * @param { function } [callback] The callback function for the download complete pause or remove change event. 1295 * @syscap SystemCapability.MiscServices.Download 1296 * @crossplatform 1297 * @since 10 1298 */ 1299 off(type: 'complete' | 'pause' | 'remove', callback?: () => void): void; 1300 1301 /** 1302 * Called when the current download session fails. 1303 * 1304 * @permission ohos.permission.INTERNET 1305 * @param { 'fail' } type Indicates the download session type, fail: download task has failed. 1306 * @param { function } callback The callback function for the download fail change event 1307 * err The error code for download task. 1308 * @syscap SystemCapability.MiscServices.Download 1309 * @since 7 1310 */ 1311 /** 1312 * Called when the current download session fails. 1313 * 1314 * @permission ohos.permission.INTERNET 1315 * @param { 'fail' } type Indicates the download session type, fail: download task has failed. 1316 * @param { function } callback The callback function for the download fail change event 1317 * err The error code for download task. 1318 * @syscap SystemCapability.MiscServices.Download 1319 * @crossplatform 1320 * @since 10 1321 */ 1322 on(type: 'fail', callback: (err: number) => void): void; 1323 1324 /** 1325 * Called when the current download session fails. 1326 * 1327 * @permission ohos.permission.INTERNET 1328 * @param { 'fail' } type Indicates the download session type, fail: download task has failed. 1329 * @param { function } [callback] Indicate the callback function to receive err. 1330 * err The error code for download task. 1331 * @syscap SystemCapability.MiscServices.Download 1332 * @since 7 1333 */ 1334 /** 1335 * Called when the current download session fails. 1336 * 1337 * @permission ohos.permission.INTERNET 1338 * @param { 'fail' } type Indicates the download session type, fail: download task has failed. 1339 * @param { function } [callback] Indicate the callback function to receive err. 1340 * err The error code for download task. 1341 * @syscap SystemCapability.MiscServices.Download 1342 * @crossplatform 1343 * @since 10 1344 */ 1345 off(type: 'fail', callback?: (err: number) => void): void; 1346 1347 /** 1348 * Deletes a download session and the downloaded files. 1349 * 1350 * @permission ohos.permission.INTERNET 1351 * @param { AsyncCallback<boolean> } callback Indicates asynchronous invoking Result. 1352 * @syscap SystemCapability.MiscServices.Download 1353 * @since 6 1354 * @deprecated since 9 1355 * @useinstead ohos.request.delete 1356 */ 1357 remove(callback: AsyncCallback<boolean>): void; 1358 1359 /** 1360 * Deletes a download session and the downloaded files. 1361 * 1362 * @permission ohos.permission.INTERNET 1363 * @returns { Promise<boolean> } the promise returned by the function. 1364 * @syscap SystemCapability.MiscServices.Download 1365 * @since 6 1366 * @deprecated since 9 1367 * @useinstead ohos.request.delete 1368 */ 1369 remove(): Promise<boolean>; 1370 1371 /** 1372 * Pause a download session. 1373 * 1374 * @permission ohos.permission.INTERNET 1375 * @param { AsyncCallback<void> } callback Indicates asynchronous invoking Result. 1376 * @syscap SystemCapability.MiscServices.Download 1377 * @since 7 1378 * @deprecated since 9 1379 * @useinstead ohos.request.suspend 1380 */ 1381 pause(callback: AsyncCallback<void>): void; 1382 1383 /** 1384 * Pause a download session. 1385 * 1386 * @permission ohos.permission.INTERNET 1387 * @returns { Promise<void> } the promise returned by the function. 1388 * @syscap SystemCapability.MiscServices.Download 1389 * @since 7 1390 * @deprecated since 9 1391 * @useinstead ohos.request.suspend 1392 */ 1393 pause(): Promise<void>; 1394 1395 /** 1396 * Resume a paused download session. 1397 * 1398 * @permission ohos.permission.INTERNET 1399 * @param { AsyncCallback<void> } callback Indicates asynchronous invoking Result. 1400 * @syscap SystemCapability.MiscServices.Download 1401 * @since 7 1402 * @deprecated since 9 1403 * @useinstead ohos.request.restore 1404 */ 1405 resume(callback: AsyncCallback<void>): void; 1406 1407 /** 1408 * Resume a paused download session. 1409 * 1410 * @permission ohos.permission.INTERNET 1411 * @returns { Promise<void> } the promise returned by the function. 1412 * @syscap SystemCapability.MiscServices.Download 1413 * @since 7 1414 * @deprecated since 9 1415 * @useinstead ohos.request.restore 1416 */ 1417 resume(): Promise<void>; 1418 1419 /** 1420 * Queries download information of a session, which is defined in DownloadSession.DownloadInfo. 1421 * 1422 * @permission ohos.permission.INTERNET 1423 * @param { AsyncCallback<DownloadInfo> } callback Indicate the callback function to receive download info. 1424 * @syscap SystemCapability.MiscServices.Download 1425 * @since 7 1426 * @deprecated since 9 1427 * @useinstead ohos.request.getTaskInfo 1428 */ 1429 query(callback: AsyncCallback<DownloadInfo>): void; 1430 1431 /** 1432 * Queries download information of a session, which is defined in DownloadSession.DownloadInfo. 1433 * 1434 * @permission ohos.permission.INTERNET 1435 * @returns { Promise<DownloadInfo> } the promise returned by the function. 1436 * @syscap SystemCapability.MiscServices.Download 1437 * @since 7 1438 * @deprecated since 9 1439 * @useinstead ohos.request.getTaskInfo 1440 */ 1441 query(): Promise<DownloadInfo>; 1442 1443 /** 1444 * Queries the MIME type of the download file. 1445 * 1446 * @permission ohos.permission.INTERNET 1447 * @param { AsyncCallback<string> } callback Indicate the callback function to receive download file MIME type. 1448 * @syscap SystemCapability.MiscServices.Download 1449 * @since 7 1450 * @deprecated since 9 1451 * @useinstead ohos.request.getTaskMimeType 1452 */ 1453 queryMimeType(callback: AsyncCallback<string>): void; 1454 1455 /** 1456 * Queries the MIME type of the download file. 1457 * 1458 * @permission ohos.permission.INTERNET 1459 * @returns { Promise<string> } the promise returned by the function. 1460 * @syscap SystemCapability.MiscServices.Download 1461 * @since 7 1462 * @deprecated since 9 1463 * @useinstead ohos.request.getTaskMimeType 1464 */ 1465 queryMimeType(): Promise<string>; 1466 1467 /** 1468 * Delete the download task 1469 * 1470 * @permission ohos.permission.INTERNET 1471 * @param { AsyncCallback<boolean> } callback 1472 * @throws { BusinessError } 201 - the permissions check fails 1473 * @throws { BusinessError } 401 - the parameters check fails 1474 * @syscap SystemCapability.MiscServices.Download 1475 * @since 9 1476 */ 1477 /** 1478 * Delete the download task 1479 * 1480 * @permission ohos.permission.INTERNET 1481 * @param { AsyncCallback<boolean> } callback 1482 * @throws { BusinessError } 201 - the permissions check fails 1483 * @throws { BusinessError } 401 - the parameters check fails 1484 * @syscap SystemCapability.MiscServices.Download 1485 * @crossplatform 1486 * @since 10 1487 */ 1488 delete(callback: AsyncCallback<boolean>): void; 1489 1490 /** 1491 * Delete the download task 1492 * 1493 * @permission ohos.permission.INTERNET 1494 * @returns { Promise<boolean> } the promise returned by the function. 1495 * @throws { BusinessError } 201 - the permissions check fails 1496 * @throws { BusinessError } 401 - the parameters check fails 1497 * @syscap SystemCapability.MiscServices.Download 1498 * @since 9 1499 */ 1500 /** 1501 * Delete the download task 1502 * 1503 * @permission ohos.permission.INTERNET 1504 * @returns { Promise<boolean> } the promise returned by the function. 1505 * @throws { BusinessError } 201 - the permissions check fails 1506 * @throws { BusinessError } 401 - the parameters check fails 1507 * @syscap SystemCapability.MiscServices.Download 1508 * @crossplatform 1509 * @since 10 1510 */ 1511 delete(): Promise<boolean>; 1512 1513 /** 1514 * Suspend the download task 1515 * 1516 * @permission ohos.permission.INTERNET 1517 * @param { AsyncCallback<boolean> } callback 1518 * @throws { BusinessError } 201 - the permissions check fails 1519 * @throws { BusinessError } 401 - the parameters check fails 1520 * @syscap SystemCapability.MiscServices.Download 1521 * @since 9 1522 */ 1523 /** 1524 * Suspend the download task 1525 * 1526 * @permission ohos.permission.INTERNET 1527 * @param { AsyncCallback<boolean> } callback 1528 * @throws { BusinessError } 201 - the permissions check fails 1529 * @throws { BusinessError } 401 - the parameters check fails 1530 * @syscap SystemCapability.MiscServices.Download 1531 * @crossplatform 1532 * @since 10 1533 */ 1534 suspend(callback: AsyncCallback<boolean>): void; 1535 1536 /** 1537 * Suspend the download task 1538 * 1539 * @permission ohos.permission.INTERNET 1540 * @returns { Promise<boolean> } the promise returned by the function. 1541 * @throws { BusinessError } 201 - the permissions check fails 1542 * @throws { BusinessError } 401 - the parameters check fails 1543 * @syscap SystemCapability.MiscServices.Download 1544 * @since 9 1545 */ 1546 /** 1547 * Suspend the download task 1548 * 1549 * @permission ohos.permission.INTERNET 1550 * @returns { Promise<boolean> } the promise returned by the function. 1551 * @throws { BusinessError } 201 - the permissions check fails 1552 * @throws { BusinessError } 401 - the parameters check fails 1553 * @syscap SystemCapability.MiscServices.Download 1554 * @crossplatform 1555 * @since 10 1556 */ 1557 suspend(): Promise<boolean>; 1558 1559 /** 1560 * Restore the download task 1561 * 1562 * @permission ohos.permission.INTERNET 1563 * @param { AsyncCallback<boolean> } callback 1564 * @throws { BusinessError } 201 - the permissions check fails 1565 * @throws { BusinessError } 401 - the parameters check fails 1566 * @syscap SystemCapability.MiscServices.Download 1567 * @since 9 1568 */ 1569 /** 1570 * Restore the download task 1571 * 1572 * @permission ohos.permission.INTERNET 1573 * @param { AsyncCallback<boolean> } callback 1574 * @throws { BusinessError } 201 - the permissions check fails 1575 * @throws { BusinessError } 401 - the parameters check fails 1576 * @syscap SystemCapability.MiscServices.Download 1577 * @crossplatform 1578 * @since 10 1579 */ 1580 restore(callback: AsyncCallback<boolean>): void; 1581 1582 /** 1583 * Restore the download task 1584 * 1585 * @permission ohos.permission.INTERNET 1586 * @returns { Promise<boolean> } the promise returned by the function. 1587 * @throws { BusinessError } 201 - the permissions check fails 1588 * @throws { BusinessError } 401 - the parameters check fails 1589 * @syscap SystemCapability.MiscServices.Download 1590 * @since 9 1591 */ 1592 /** 1593 * Restore the download task 1594 * 1595 * @permission ohos.permission.INTERNET 1596 * @returns { Promise<boolean> } the promise returned by the function. 1597 * @throws { BusinessError } 201 - the permissions check fails 1598 * @throws { BusinessError } 401 - the parameters check fails 1599 * @syscap SystemCapability.MiscServices.Download 1600 * @crossplatform 1601 * @since 10 1602 */ 1603 restore(): Promise<boolean>; 1604 1605 /** 1606 * Get the download task info 1607 * 1608 * @permission ohos.permission.INTERNET 1609 * @param { AsyncCallback<DownloadInfo> } callback 1610 * @throws { BusinessError } 201 - the permissions check fails 1611 * @throws { BusinessError } 401 - the parameters check fails 1612 * @syscap SystemCapability.MiscServices.Download 1613 * @since 9 1614 */ 1615 /** 1616 * Get the download task info 1617 * 1618 * @permission ohos.permission.INTERNET 1619 * @param { AsyncCallback<DownloadInfo> } callback 1620 * @throws { BusinessError } 201 - the permissions check fails 1621 * @throws { BusinessError } 401 - the parameters check fails 1622 * @syscap SystemCapability.MiscServices.Download 1623 * @crossplatform 1624 * @since 10 1625 */ 1626 getTaskInfo(callback: AsyncCallback<DownloadInfo>): void; 1627 1628 /** 1629 * Get the download task info 1630 * 1631 * @permission ohos.permission.INTERNET 1632 * @returns { Promise<DownloadInfo> } the promise returned by the function. 1633 * @throws { BusinessError } 201 - the permissions check fails 1634 * @throws { BusinessError } 401 - the parameters check fails 1635 * @syscap SystemCapability.MiscServices.Download 1636 * @since 9 1637 */ 1638 /** 1639 * Get the download task info 1640 * 1641 * @permission ohos.permission.INTERNET 1642 * @returns { Promise<DownloadInfo> } the promise returned by the function. 1643 * @throws { BusinessError } 201 - the permissions check fails 1644 * @throws { BusinessError } 401 - the parameters check fails 1645 * @syscap SystemCapability.MiscServices.Download 1646 * @crossplatform 1647 * @since 10 1648 */ 1649 getTaskInfo(): Promise<DownloadInfo>; 1650 1651 /** 1652 * Get mimetype of the download task 1653 * 1654 * @permission ohos.permission.INTERNET 1655 * @param { AsyncCallback<string> } callback 1656 * @throws { BusinessError } 201 - the permissions check fails 1657 * @throws { BusinessError } 401 - the parameters check fails 1658 * @syscap SystemCapability.MiscServices.Download 1659 * @since 9 1660 */ 1661 /** 1662 * Get mimetype of the download task 1663 * 1664 * @permission ohos.permission.INTERNET 1665 * @param { AsyncCallback<string> } callback 1666 * @throws { BusinessError } 201 - the permissions check fails 1667 * @throws { BusinessError } 401 - the parameters check fails 1668 * @syscap SystemCapability.MiscServices.Download 1669 * @crossplatform 1670 * @since 10 1671 */ 1672 getTaskMimeType(callback: AsyncCallback<string>): void; 1673 1674 /** 1675 * Get mimetype of the download task 1676 * 1677 * @permission ohos.permission.INTERNET 1678 * @returns { Promise<string> } the promise returned by the function. 1679 * @throws { BusinessError } 201 - the permissions check fails 1680 * @throws { BusinessError } 401 - the parameters check fails 1681 * @syscap SystemCapability.MiscServices.Download 1682 * @since 9 1683 */ 1684 /** 1685 * Get mimetype of the download task 1686 * 1687 * @permission ohos.permission.INTERNET 1688 * @returns { Promise<string> } the promise returned by the function. 1689 * @throws { BusinessError } 201 - the permissions check fails 1690 * @throws { BusinessError } 401 - the parameters check fails 1691 * @syscap SystemCapability.MiscServices.Download 1692 * @crossplatform 1693 * @since 10 1694 */ 1695 getTaskMimeType(): Promise<string>; 1696 } 1697 1698 /** 1699 * File data Structure 1700 * 1701 * @interface File 1702 * @permission ohos.permission.INTERNET 1703 * @syscap SystemCapability.MiscServices.Download 1704 * @since 6 1705 * @name File 1706 */ 1707 /** 1708 * File data Structure 1709 * 1710 * @typedef File 1711 * @permission ohos.permission.INTERNET 1712 * @syscap SystemCapability.MiscServices.Download 1713 * @crossplatform 1714 * @since 10 1715 */ 1716 interface File { 1717 /** 1718 * When multipart is submitted, the file name in the request header. 1719 * 1720 * @permission ohos.permission.INTERNET 1721 * @syscap SystemCapability.MiscServices.Download 1722 * @since 6 1723 */ 1724 /** 1725 * When multipart is submitted, the file name in the request header. 1726 * 1727 * @permission ohos.permission.INTERNET 1728 * @type { string } 1729 * @syscap SystemCapability.MiscServices.Download 1730 * @crossplatform 1731 * @since 10 1732 */ 1733 filename: string; 1734 /** 1735 * When multipart is submitted, the name of the form item. The default is file. 1736 * 1737 * @permission ohos.permission.INTERNET 1738 * @syscap SystemCapability.MiscServices.Download 1739 * @since 6 1740 */ 1741 /** 1742 * When multipart is submitted, the name of the form item. The default is file. 1743 * 1744 * @permission ohos.permission.INTERNET 1745 * @type { string } 1746 * @syscap SystemCapability.MiscServices.Download 1747 * @crossplatform 1748 * @since 10 1749 */ 1750 name: string; 1751 /** 1752 * The local storage path of the file (please refer to the storage directory definition for path usage). 1753 * 1754 * @permission ohos.permission.INTERNET 1755 * @syscap SystemCapability.MiscServices.Download 1756 * @since 6 1757 */ 1758 /** 1759 * The local storage path of the file (please refer to the storage directory definition for path usage). 1760 * 1761 * @permission ohos.permission.INTERNET 1762 * @type { string } 1763 * @syscap SystemCapability.MiscServices.Download 1764 * @crossplatform 1765 * @since 10 1766 */ 1767 uri: string; 1768 /** 1769 * The content type of the file is obtained by default according to the suffix of the file name or path. 1770 * 1771 * @permission ohos.permission.INTERNET 1772 * @syscap SystemCapability.MiscServices.Download 1773 * @since 6 1774 */ 1775 /** 1776 * The content type of the file is obtained by default according to the suffix of the file name or path. 1777 * 1778 * @permission ohos.permission.INTERNET 1779 * @type { string } 1780 * @syscap SystemCapability.MiscServices.Download 1781 * @crossplatform 1782 * @since 10 1783 */ 1784 type: string; 1785 } 1786 1787 /** 1788 * RequestData data Structure 1789 * 1790 * @interface RequestData 1791 * @permission ohos.permission.INTERNET 1792 * @syscap SystemCapability.MiscServices.Download 1793 * @since 6 1794 * @name RequestData 1795 */ 1796 /** 1797 * RequestData data Structure 1798 * 1799 * @typedef RequestData 1800 * @permission ohos.permission.INTERNET 1801 * @syscap SystemCapability.MiscServices.Download 1802 * @crossplatform 1803 * @since 10 1804 */ 1805 interface RequestData { 1806 /** 1807 * Represents the name of the form element. 1808 * 1809 * @permission ohos.permission.INTERNET 1810 * @syscap SystemCapability.MiscServices.Download 1811 * @since 6 1812 */ 1813 /** 1814 * Represents the name of the form element. 1815 * 1816 * @permission ohos.permission.INTERNET 1817 * @type { string } 1818 * @syscap SystemCapability.MiscServices.Download 1819 * @crossplatform 1820 * @since 10 1821 */ 1822 name: string; 1823 /** 1824 * Represents the value of the form element. 1825 * 1826 * @permission ohos.permission.INTERNET 1827 * @syscap SystemCapability.MiscServices.Download 1828 * @since 6 1829 */ 1830 /** 1831 * Represents the value of the form element. 1832 * 1833 * @permission ohos.permission.INTERNET 1834 * @type { string } 1835 * @syscap SystemCapability.MiscServices.Download 1836 * @crossplatform 1837 * @since 10 1838 */ 1839 value: string; 1840 } 1841 1842 /** 1843 * UploadConfig data Structure 1844 * 1845 * @interface UploadConfig 1846 * @permission ohos.permission.INTERNET 1847 * @syscap SystemCapability.MiscServices.Upload 1848 * @since 6 1849 * @name UploadConfig 1850 */ 1851 /** 1852 * UploadConfig data Structure 1853 * 1854 * @typedef UploadConfig 1855 * @permission ohos.permission.INTERNET 1856 * @syscap SystemCapability.MiscServices.Upload 1857 * @crossplatform 1858 * @since 10 1859 */ 1860 interface UploadConfig { 1861 /** 1862 * Resource address. 1863 * 1864 * @permission ohos.permission.INTERNET 1865 * @syscap SystemCapability.MiscServices.Upload 1866 * @since 6 1867 */ 1868 /** 1869 * Resource address. 1870 * 1871 * @permission ohos.permission.INTERNET 1872 * @type { string } 1873 * @syscap SystemCapability.MiscServices.Upload 1874 * @crossplatform 1875 * @since 10 1876 */ 1877 url: string; 1878 /** 1879 * Adds an HTTP or HTTPS header to be included with the upload request. 1880 * 1881 * @permission ohos.permission.INTERNET 1882 * @syscap SystemCapability.MiscServices.Upload 1883 * @since 6 1884 */ 1885 /** 1886 * Adds an HTTP or HTTPS header to be included with the upload request. 1887 * 1888 * @permission ohos.permission.INTERNET 1889 * @type { Object } 1890 * @syscap SystemCapability.MiscServices.Upload 1891 * @crossplatform 1892 * @since 10 1893 */ 1894 header: Object; 1895 /** 1896 * Request method: POST, PUT. The default POST. 1897 * 1898 * @permission ohos.permission.INTERNET 1899 * @syscap SystemCapability.MiscServices.Upload 1900 * @since 6 1901 */ 1902 /** 1903 * Request method: POST, PUT. The default POST. 1904 * 1905 * @permission ohos.permission.INTERNET 1906 * @type { string } 1907 * @syscap SystemCapability.MiscServices.Upload 1908 * @crossplatform 1909 * @since 10 1910 */ 1911 method: string; 1912 /** 1913 * The index of paths for a task. 1914 * Usually used for a continuous job. 1915 * The default is 0. 1916 * 1917 * @type { ?number } 1918 * @syscap SystemCapability.MiscServices.Upload 1919 * @since 11 1920 */ 1921 index?: number; 1922 /** 1923 * The start point of a file. 1924 * Usually used for a continuous job. 1925 * It will start read at the point in upload. 1926 * The default is 0. 1927 * 1928 * @type { ?number } 1929 * @syscap SystemCapability.MiscServices.Upload 1930 * @since 11 1931 */ 1932 begins?: number; 1933 /** 1934 * The end point of a file. 1935 * Usually used for a continuous job. 1936 * It will end read at the point in upload. 1937 * The default is -1 indicating the end of the data for upload. 1938 * 1939 * @type { ?number } 1940 * @syscap SystemCapability.MiscServices.Upload 1941 * @since 11 1942 */ 1943 ends?: number; 1944 /** 1945 * A list of files to be uploaded. Please use multipart/form-data to submit. 1946 * 1947 * @permission ohos.permission.INTERNET 1948 * @syscap SystemCapability.MiscServices.Upload 1949 * @since 6 1950 */ 1951 /** 1952 * A list of files to be uploaded. Please use multipart/form-data to submit. 1953 * 1954 * @permission ohos.permission.INTERNET 1955 * @type { Array<File> } 1956 * @syscap SystemCapability.MiscServices.Upload 1957 * @crossplatform 1958 * @since 10 1959 */ 1960 files: Array<File>; 1961 /** 1962 * The requested form data. 1963 * 1964 * @permission ohos.permission.INTERNET 1965 * @syscap SystemCapability.MiscServices.Upload 1966 * @since 6 1967 */ 1968 /** 1969 * The requested form data. 1970 * 1971 * @permission ohos.permission.INTERNET 1972 * @type { Array<RequestData> } 1973 * @syscap SystemCapability.MiscServices.Upload 1974 * @crossplatform 1975 * @since 10 1976 */ 1977 data: Array<RequestData>; 1978 } 1979 1980 /** 1981 * TaskState data Structure 1982 * 1983 * @interface TaskState 1984 * @permission ohos.permission.INTERNET 1985 * @syscap SystemCapability.MiscServices.Upload 1986 * @since 9 1987 * @name TaskState 1988 */ 1989 /** 1990 * TaskState data Structure 1991 * 1992 * @typedef TaskState 1993 * @permission ohos.permission.INTERNET 1994 * @syscap SystemCapability.MiscServices.Upload 1995 * @crossplatform 1996 * @since 10 1997 */ 1998 interface TaskState { 1999 /** 2000 * Upload file path. 2001 * 2002 * @permission ohos.permission.INTERNET 2003 * @syscap SystemCapability.MiscServices.Upload 2004 * @since 9 2005 */ 2006 /** 2007 * Upload file path. 2008 * 2009 * @permission ohos.permission.INTERNET 2010 * @type { string } 2011 * @syscap SystemCapability.MiscServices.Upload 2012 * @crossplatform 2013 * @since 10 2014 */ 2015 path: string; 2016 /** 2017 * Upload task return value. 2018 * 2019 * @permission ohos.permission.INTERNET 2020 * @syscap SystemCapability.MiscServices.Upload 2021 * @since 9 2022 */ 2023 /** 2024 * Upload task return value. 2025 * 2026 * @permission ohos.permission.INTERNET 2027 * @type { number } 2028 * @syscap SystemCapability.MiscServices.Upload 2029 * @crossplatform 2030 * @since 10 2031 */ 2032 responseCode: number; 2033 /** 2034 * Upload task information. 2035 * 2036 * @permission ohos.permission.INTERNET 2037 * @syscap SystemCapability.MiscServices.Upload 2038 * @since 9 2039 */ 2040 /** 2041 * Upload task information. 2042 * 2043 * @permission ohos.permission.INTERNET 2044 * @type { string } 2045 * @syscap SystemCapability.MiscServices.Upload 2046 * @crossplatform 2047 * @since 10 2048 */ 2049 message: string; 2050 } 2051 2052 /** 2053 * Upload task interface 2054 * 2055 * @interface UploadTask 2056 * @permission ohos.permission.INTERNET 2057 * @syscap SystemCapability.MiscServices.Download 2058 * @since 6 2059 */ 2060 /** 2061 * Upload task interface 2062 * 2063 * @typedef UploadTask 2064 * @permission ohos.permission.INTERNET 2065 * @syscap SystemCapability.MiscServices.Download 2066 * @crossplatform 2067 * @since 10 2068 */ 2069 interface UploadTask { 2070 /** 2071 * Called when the current upload session is in process. 2072 * 2073 * @permission ohos.permission.INTERNET 2074 * @param { 'progress' } type progress Indicates the upload task progress. 2075 * @param { function } callback 2076 * The callback function for the upload progress change event 2077 * uploadedSize The length of uploaded data, in bytes 2078 * totalSize The length of data expected to be uploaded, in bytes. 2079 * @syscap SystemCapability.MiscServices.Upload 2080 * @since 6 2081 */ 2082 /** 2083 * Called when the current upload session is in process. 2084 * 2085 * @permission ohos.permission.INTERNET 2086 * @param { 'progress' } type progress Indicates the upload task progress. 2087 * @param { function } callback 2088 * The callback function for the upload progress change event 2089 * uploadedSize The length of uploaded data, in bytes 2090 * totalSize The length of data expected to be uploaded, in bytes. 2091 * @syscap SystemCapability.MiscServices.Upload 2092 * @crossplatform 2093 * @since 10 2094 */ 2095 on(type: 'progress', callback: (uploadedSize: number, totalSize: number) => void): void; 2096 2097 /** 2098 * Called when the current upload session is in process. 2099 * 2100 * @permission ohos.permission.INTERNET 2101 * @param { 'progress' } type progress Indicates the upload task progress. 2102 * @param { function } [callback] 2103 * The callback function for the upload progress change event 2104 * uploadedSize The length of uploaded data, in bytes 2105 * totalSize The length of data expected to be uploaded, in bytes. 2106 * @syscap SystemCapability.MiscServices.Upload 2107 * @since 6 2108 */ 2109 /** 2110 * Called when the current upload session is in process. 2111 * 2112 * @permission ohos.permission.INTERNET 2113 * @param { 'progress' } type progress Indicates the upload task progress. 2114 * @param { function } [callback] 2115 * The callback function for the upload progress change event 2116 * uploadedSize The length of uploaded data, in bytes 2117 * totalSize The length of data expected to be uploaded, in bytes. 2118 * @syscap SystemCapability.MiscServices.Upload 2119 * @crossplatform 2120 * @since 10 2121 */ 2122 off(type: 'progress', callback?: (uploadedSize: number, totalSize: number) => void): void; 2123 2124 /** 2125 * Called when the header of the current upload session has been received. 2126 * 2127 * @permission ohos.permission.INTERNET 2128 * @param { 'headerReceive' } type headerReceive Indicates the upload task headed receive. 2129 * @param { function } callback The callback function for the HTTP Response Header event 2130 * header HTTP Response Header returned by the developer server. 2131 * @syscap SystemCapability.MiscServices.Upload 2132 * @since 7 2133 */ 2134 /** 2135 * Called when the header of the current upload session has been received. 2136 * 2137 * @permission ohos.permission.INTERNET 2138 * @param { 'headerReceive' } type headerReceive Indicates the upload task headed receive. 2139 * @param { function } callback The callback function for the HTTP Response Header event 2140 * header HTTP Response Header returned by the developer server. 2141 * @syscap SystemCapability.MiscServices.Upload 2142 * @crossplatform 2143 * @since 10 2144 */ 2145 on(type: 'headerReceive', callback: (header: object) => void): void; 2146 2147 /** 2148 * Called when the header of the current upload session has been received. 2149 * 2150 * @permission ohos.permission.INTERNET 2151 * @param { 'headerReceive' } type headerReceive Indicates the upload task headed receive. 2152 * @param { function } [callback] The callback function for the HTTP Response Header event 2153 * header HTTP Response Header returned by the developer server. 2154 * @syscap SystemCapability.MiscServices.Upload 2155 * @since 7 2156 */ 2157 /** 2158 * Called when the header of the current upload session has been received. 2159 * 2160 * @permission ohos.permission.INTERNET 2161 * @param { 'headerReceive' } type headerReceive Indicates the upload task headed receive. 2162 * @param { function } [callback] The callback function for the HTTP Response Header event 2163 * header HTTP Response Header returned by the developer server. 2164 * @syscap SystemCapability.MiscServices.Upload 2165 * @crossplatform 2166 * @since 10 2167 */ 2168 off(type: 'headerReceive', callback?: (header: object) => void): void; 2169 2170 /** 2171 * Called when the current upload session complete or fail. 2172 * 2173 * @permission ohos.permission.INTERNET 2174 * @param { 'complete' | 'fail' } type Indicates the upload session event type 2175 * complete: upload task completed 2176 * fail: upload task failed 2177 * @param { Callback<Array<TaskState>> } callback The callback function for the upload complete or fail change event. 2178 * @syscap SystemCapability.MiscServices.Upload 2179 * @since 9 2180 */ 2181 /** 2182 * Called when the current upload session complete or fail. 2183 * 2184 * @permission ohos.permission.INTERNET 2185 * @param { 'complete' | 'fail' } type Indicates the upload session event type 2186 * complete: upload task completed 2187 * fail: upload task failed 2188 * @param { Callback<Array<TaskState>> } callback The callback function for the upload complete or fail change event. 2189 * @syscap SystemCapability.MiscServices.Upload 2190 * @crossplatform 2191 * @since 10 2192 */ 2193 on(type: 'complete' | 'fail', callback: Callback<Array<TaskState>>): void; 2194 2195 /** 2196 * Called when the current upload session complete or fail. 2197 * 2198 * @permission ohos.permission.INTERNET 2199 * @param { 'complete' | 'fail' } type Indicates the upload session event type 2200 * complete: upload task completed 2201 * fail: upload task failed 2202 * @param { Callback<Array<TaskState>> } [callback] 2203 * @syscap SystemCapability.MiscServices.Upload 2204 * @since 9 2205 */ 2206 /** 2207 * Called when the current upload session complete or fail. 2208 * 2209 * @permission ohos.permission.INTERNET 2210 * @param { 'complete' | 'fail' } type Indicates the upload session event type 2211 * complete: upload task completed 2212 * fail: upload task failed 2213 * @param { Callback<Array<TaskState>> } [callback] 2214 * @syscap SystemCapability.MiscServices.Upload 2215 * @crossplatform 2216 * @since 10 2217 */ 2218 off(type: 'complete' | 'fail', callback?: Callback<Array<TaskState>>): void; 2219 2220 /** 2221 * Deletes a upload session. 2222 * 2223 * @permission ohos.permission.INTERNET 2224 * @param { AsyncCallback<boolean> } callback Indicates asynchronous invoking Result. 2225 * @syscap SystemCapability.MiscServices.Upload 2226 * @since 6 2227 * @deprecated since 9 2228 * @useinstead ohos.request.delete 2229 */ 2230 remove(callback: AsyncCallback<boolean>): void; 2231 2232 /** 2233 * Deletes a upload session. 2234 * 2235 * @permission ohos.permission.INTERNET 2236 * @returns { Promise<boolean> } the promise returned by the function. 2237 * @syscap SystemCapability.MiscServices.Upload 2238 * @since 6 2239 * @deprecated since 9 2240 * @useinstead ohos.request.delete 2241 */ 2242 remove(): Promise<boolean>; 2243 2244 /** 2245 * Delete the upload task 2246 * 2247 * @permission ohos.permission.INTERNET 2248 * @param { AsyncCallback<boolean> } callback 2249 * @throws { BusinessError } 201 - the permissions check fails 2250 * @throws { BusinessError } 401 - the parameters check fails 2251 * @syscap SystemCapability.MiscServices.Upload 2252 * @since 9 2253 */ 2254 /** 2255 * Delete the upload task 2256 * 2257 * @permission ohos.permission.INTERNET 2258 * @param { AsyncCallback<boolean> } callback 2259 * @throws { BusinessError } 201 - the permissions check fails 2260 * @throws { BusinessError } 401 - the parameters check fails 2261 * @syscap SystemCapability.MiscServices.Upload 2262 * @crossplatform 2263 * @since 10 2264 */ 2265 delete(callback: AsyncCallback<boolean>): void; 2266 2267 /** 2268 * Delete the upload task 2269 * 2270 * @permission ohos.permission.INTERNET 2271 * @returns { Promise<boolean> } the promise returned by the function. 2272 * @throws { BusinessError } 201 - the permissions check fails 2273 * @throws { BusinessError } 401 - the parameters check fails 2274 * @syscap SystemCapability.MiscServices.Upload 2275 * @since 9 2276 */ 2277 /** 2278 * Delete the upload task 2279 * 2280 * @permission ohos.permission.INTERNET 2281 * @returns { Promise<boolean> } the promise returned by the function. 2282 * @throws { BusinessError } 201 - the permissions check fails 2283 * @throws { BusinessError } 401 - the parameters check fails 2284 * @syscap SystemCapability.MiscServices.Upload 2285 * @crossplatform 2286 * @since 10 2287 */ 2288 delete(): Promise<boolean>; 2289 } 2290 2291 /** 2292 * The request agent api. 2293 * Supports "background" and "frontend" tasks as while. 2294 * Though "background" and "frontend" here do not the same with process's concept. 2295 * All tasks will be executed at request manager service and recorded. 2296 * Background tasks is for concurrent transfer, such as caching videos for a later play. 2297 * Frontend tasks is for instant transfer, such as submitting forms for a consumption bill. 2298 * Background tasks use notification to tell user tasks' status information. 2299 * Frontend tasks use callback to tell caller tasks' status information. 2300 * Background has some automatically restore mechanism. 2301 * Frontend tasks controlled by caller. 2302 * Uses `multipart/form-data` in client request for upload. 2303 * A `Content-Disposition: attachment; filename=<filename>` response from server leads to download. 2304 * More details, please see the architecture documents of the request subsystem. 2305 * 2306 * @namespace agent 2307 * @syscap SystemCapability.Request.FileTransferAgent 2308 * @since 10 2309 */ 2310 /** 2311 * The request agent api. 2312 * Supports "background" and "frontend" tasks as while. 2313 * Though "background" and "frontend" here do not the same with process's concept. 2314 * All tasks will be executed at request manager service and recorded. 2315 * Background tasks is for concurrent transfer, such as caching videos for a later play. 2316 * Frontend tasks is for instant transfer, such as submitting forms for a consumption bill. 2317 * Background tasks use notification to tell user tasks' status information. 2318 * Frontend tasks use callback to tell caller tasks' status information. 2319 * Background has some automatically restore mechanism. 2320 * Frontend tasks controlled by caller. 2321 * Uses `multipart/form-data` in client request for upload. 2322 * A `Content-Disposition: attachment; filename=<filename>` response from server leads to download. 2323 * More details, please see the architecture documents of the request subsystem. 2324 * Only front-end mode is supported in cross-platform scenarios. 2325 * 2326 * @namespace agent 2327 * @syscap SystemCapability.Request.FileTransferAgent 2328 * @crossplatform 2329 * @atomicservice 2330 * @since 11 2331 */ 2332 namespace agent { 2333 /** 2334 * The action options. 2335 * 2336 * @enum { number } Action 2337 * @syscap SystemCapability.Request.FileTransferAgent 2338 * @since 10 2339 */ 2340 /** 2341 * The action options. 2342 * 2343 * @enum { number } Action 2344 * @syscap SystemCapability.Request.FileTransferAgent 2345 * @crossplatform 2346 * @atomicservice 2347 * @since 11 2348 */ 2349 enum Action { 2350 /** 2351 * Indicates download task. 2352 * 2353 * @syscap SystemCapability.Request.FileTransferAgent 2354 * @since 10 2355 */ 2356 /** 2357 * Indicates download task. 2358 * 2359 * @syscap SystemCapability.Request.FileTransferAgent 2360 * @crossplatform 2361 * @atomicservice 2362 * @since 11 2363 */ 2364 DOWNLOAD, 2365 /** 2366 * Indicates upload task. 2367 * 2368 * @syscap SystemCapability.Request.FileTransferAgent 2369 * @since 10 2370 */ 2371 /** 2372 * Indicates upload task. 2373 * 2374 * @syscap SystemCapability.Request.FileTransferAgent 2375 * @crossplatform 2376 * @atomicservice 2377 * @since 11 2378 */ 2379 UPLOAD 2380 } 2381 2382 /** 2383 * The mode options. 2384 * 2385 * @enum { number } Mode 2386 * @syscap SystemCapability.Request.FileTransferAgent 2387 * @since 10 2388 */ 2389 /** 2390 * The mode options. 2391 * 2392 * @enum { number } Mode 2393 * @syscap SystemCapability.Request.FileTransferAgent 2394 * @crossplatform 2395 * @atomicservice 2396 * @since 11 2397 */ 2398 enum Mode { 2399 /** 2400 * Indicates background task. 2401 * 2402 * @syscap SystemCapability.Request.FileTransferAgent 2403 * @since 10 2404 */ 2405 /** 2406 * Indicates background task. 2407 * 2408 * @syscap SystemCapability.Request.FileTransferAgent 2409 * @atomicservice 2410 * @since 11 2411 */ 2412 BACKGROUND, 2413 /** 2414 * Indicates foreground task. 2415 * 2416 * @syscap SystemCapability.Request.FileTransferAgent 2417 * @since 10 2418 */ 2419 /** 2420 * Indicates foreground task. 2421 * 2422 * @syscap SystemCapability.Request.FileTransferAgent 2423 * @crossplatform 2424 * @atomicservice 2425 * @since 11 2426 */ 2427 FOREGROUND 2428 } 2429 2430 /** 2431 * The network options. 2432 * 2433 * @enum { number } Network 2434 * @syscap SystemCapability.Request.FileTransferAgent 2435 * @since 10 2436 */ 2437 /** 2438 * The network options. 2439 * 2440 * @enum { number } Network 2441 * @syscap SystemCapability.Request.FileTransferAgent 2442 * @crossplatform 2443 * @atomicservice 2444 * @since 11 2445 */ 2446 enum Network { 2447 /** 2448 * Indicates no restriction on network type. 2449 * 2450 * @syscap SystemCapability.Request.FileTransferAgent 2451 * @since 10 2452 */ 2453 /** 2454 * Indicates no restriction on network type. 2455 * 2456 * @syscap SystemCapability.Request.FileTransferAgent 2457 * @crossplatform 2458 * @atomicservice 2459 * @since 11 2460 */ 2461 ANY, 2462 /** 2463 * Indicates Wi-Fi only. 2464 * 2465 * @syscap SystemCapability.Request.FileTransferAgent 2466 * @since 10 2467 */ 2468 /** 2469 * Indicates Wi-Fi only. 2470 * 2471 * @syscap SystemCapability.Request.FileTransferAgent 2472 * @crossplatform 2473 * @atomicservice 2474 * @since 11 2475 */ 2476 WIFI, 2477 /** 2478 * Indicates cellular only. 2479 * 2480 * @syscap SystemCapability.Request.FileTransferAgent 2481 * @since 10 2482 */ 2483 /** 2484 * Indicates cellular only. 2485 * 2486 * @syscap SystemCapability.Request.FileTransferAgent 2487 * @crossplatform 2488 * @atomicservice 2489 * @since 11 2490 */ 2491 CELLULAR 2492 } 2493 2494 /** 2495 * Broadcast events for the request. 2496 * 2497 * @enum { string } BroadcastEvent 2498 * @syscap SystemCapability.Request.FileTransferAgent 2499 * @since 11 2500 */ 2501 enum BroadcastEvent { 2502 /** 2503 * Completion event for the task. 2504 * The code in the commonEventData can only be "0x40"(COMPLETE) or "0x41"(FAILED), same as "State". 2505 * The data in the commonEventData contains the id of the task. 2506 * 2507 * @syscap SystemCapability.Request.FileTransferAgent 2508 * @since 11 2509 */ 2510 COMPLETE = 'ohos.request.event.COMPLETE' 2511 } 2512 2513 /** 2514 * The file information for a form item. 2515 * 2516 * @typedef FileSpec 2517 * @syscap SystemCapability.Request.FileTransferAgent 2518 * @since 10 2519 */ 2520 /** 2521 * The file information for a form item. 2522 * 2523 * @typedef FileSpec 2524 * @syscap SystemCapability.Request.FileTransferAgent 2525 * @crossplatform 2526 * @atomicservice 2527 * @since 11 2528 */ 2529 interface FileSpec { 2530 /** 2531 * A relative path string, like "./xxx/yyy/zzz.html", "xxx/yyy/zzz.html", in the caller's cache directory. 2532 * 2533 * @type { string } 2534 * @syscap SystemCapability.Request.FileTransferAgent 2535 * @since 10 2536 */ 2537 /** 2538 * A relative path string, like "./xxx/yyy/zzz.html", "xxx/yyy/zzz.html", in the caller's cache directory. 2539 * 2540 * @type { string } 2541 * @syscap SystemCapability.Request.FileTransferAgent 2542 * @crossplatform 2543 * @atomicservice 2544 * @since 11 2545 */ 2546 path: string; 2547 /** 2548 * The MIME type of the file. 2549 * The default is obtained by the suffix of the filename. 2550 * 2551 * @type { ?string } 2552 * @syscap SystemCapability.Request.FileTransferAgent 2553 * @since 10 2554 */ 2555 /** 2556 * The MIME type of the file. 2557 * The default is obtained by the suffix of the filename. 2558 * 2559 * @type { ?string } 2560 * @syscap SystemCapability.Request.FileTransferAgent 2561 * @crossplatform 2562 * @atomicservice 2563 * @since 11 2564 */ 2565 mimeType?: string; 2566 /** 2567 * The filename, the default is obtained by path. 2568 * 2569 * @type { ?string } 2570 * @syscap SystemCapability.Request.FileTransferAgent 2571 * @since 10 2572 */ 2573 /** 2574 * The filename, the default is obtained by path. 2575 * 2576 * @type { ?string } 2577 * @syscap SystemCapability.Request.FileTransferAgent 2578 * @crossplatform 2579 * @atomicservice 2580 * @since 11 2581 */ 2582 filename?: string; 2583 /** 2584 * The extras for the file information. 2585 * 2586 * @type { ?object } 2587 * @syscap SystemCapability.Request.FileTransferAgent 2588 * @since 10 2589 */ 2590 /** 2591 * The extras for the file information. 2592 * 2593 * @type { ?object } 2594 * @syscap SystemCapability.Request.FileTransferAgent 2595 * @crossplatform 2596 * @atomicservice 2597 * @since 11 2598 */ 2599 extras?: object; 2600 } 2601 2602 /** 2603 * The form item information for a task. 2604 * 2605 * @typedef FormItem 2606 * @syscap SystemCapability.Request.FileTransferAgent 2607 * @since 10 2608 */ 2609 /** 2610 * The form item information for a task. 2611 * 2612 * @typedef FormItem 2613 * @syscap SystemCapability.Request.FileTransferAgent 2614 * @crossplatform 2615 * @atomicservice 2616 * @since 11 2617 */ 2618 interface FormItem { 2619 /** 2620 * The item's name. 2621 * 2622 * @type { string } 2623 * @syscap SystemCapability.Request.FileTransferAgent 2624 * @since 10 2625 */ 2626 /** 2627 * The item's name. 2628 * 2629 * @type { string } 2630 * @syscap SystemCapability.Request.FileTransferAgent 2631 * @crossplatform 2632 * @atomicservice 2633 * @since 11 2634 */ 2635 name: string; 2636 /** 2637 * The item's value. 2638 * 2639 * @type { string | FileSpec | Array<FileSpec> } 2640 * @syscap SystemCapability.Request.FileTransferAgent 2641 * @since 10 2642 */ 2643 /** 2644 * The item's value. 2645 * 2646 * @type { string | FileSpec | Array<FileSpec> } 2647 * @syscap SystemCapability.Request.FileTransferAgent 2648 * @crossplatform 2649 * @atomicservice 2650 * @since 11 2651 */ 2652 value: string | FileSpec | Array<FileSpec>; 2653 } 2654 2655 /** 2656 * The configurations for a task. 2657 * Using a flexible configuration for clear upload and download functions. 2658 * If without emphasis, an option is for any task. 2659 * 2660 * @typedef Config 2661 * @syscap SystemCapability.Request.FileTransferAgent 2662 * @since 10 2663 */ 2664 /** 2665 * The configurations for a task. 2666 * Using a flexible configuration for clear upload and download functions. 2667 * If without emphasis, an option is for any task. 2668 * 2669 * @typedef Config 2670 * @syscap SystemCapability.Request.FileTransferAgent 2671 * @crossplatform 2672 * @atomicservice 2673 * @since 11 2674 */ 2675 interface Config { 2676 /** 2677 * The task action, upload or download. 2678 * 2679 * @type { Action } 2680 * @syscap SystemCapability.Request.FileTransferAgent 2681 * @since 10 2682 */ 2683 /** 2684 * The task action, upload or download. 2685 * 2686 * @type { Action } 2687 * @syscap SystemCapability.Request.FileTransferAgent 2688 * @crossplatform 2689 * @atomicservice 2690 * @since 11 2691 */ 2692 action: Action; 2693 /** 2694 * The Universal Resource Locator for a task. 2695 * The maximum length is 2048 characters. 2696 * Using raw `url` option, even url parameters in it. 2697 * 2698 * @type { string } 2699 * @syscap SystemCapability.Request.FileTransferAgent 2700 * @since 10 2701 */ 2702 /** 2703 * The Universal Resource Locator for a task. 2704 * The maximum length is 2048 characters. 2705 * Using raw `url` option, even url parameters in it. 2706 * 2707 * @type { string } 2708 * @syscap SystemCapability.Request.FileTransferAgent 2709 * @crossplatform 2710 * @atomicservice 2711 * @since 11 2712 */ 2713 url: string; 2714 /** 2715 * The title for a task, give a meaningful title please. 2716 * The maximum length is 256 characters. 2717 * The default is the same with its action. 2718 * 2719 * @type { ?string } 2720 * @syscap SystemCapability.Request.FileTransferAgent 2721 * @since 10 2722 */ 2723 /** 2724 * The title for a task, give a meaningful title please. 2725 * The maximum length is 256 characters. 2726 * The default is upload or download, consistent with its action. 2727 * 2728 * @type { ?string } 2729 * @syscap SystemCapability.Request.FileTransferAgent 2730 * @crossplatform 2731 * @atomicservice 2732 * @since 11 2733 */ 2734 title?: string; 2735 /** 2736 * The details for a task. 2737 * The maximum length is 1024 characters. 2738 * The default is empty string. 2739 * 2740 * @type { ?string } 2741 * @syscap SystemCapability.Request.FileTransferAgent 2742 * @since 10 2743 */ 2744 /** 2745 * The details for a task. 2746 * The maximum length is 1024 characters. 2747 * The default is empty string. 2748 * 2749 * @type { ?string } 2750 * @syscap SystemCapability.Request.FileTransferAgent 2751 * @crossplatform 2752 * @atomicservice 2753 * @since 11 2754 */ 2755 description?: string; 2756 /** 2757 * Indicates task's mode. 2758 * The default is background. 2759 * For frontend task, it has callbacks. 2760 * For background task, it has notifications and fallback. 2761 * 2762 * @type { ?Mode } 2763 * @syscap SystemCapability.Request.FileTransferAgent 2764 * @since 10 2765 */ 2766 /** 2767 * Indicates task's mode. 2768 * The default is BACKGROUND. 2769 * For frontend task, it has callbacks. 2770 * For background task, it has notifications and fallback. 2771 * The cross-platform default is FOREGROUND. 2772 * 2773 * @type { ?Mode } 2774 * @syscap SystemCapability.Request.FileTransferAgent 2775 * @crossplatform 2776 * @atomicservice 2777 * @since 11 2778 */ 2779 2780 mode?: Mode; 2781 /** 2782 * The solution choice when path already exists during download. 2783 * Currently support: 2784 * true, rewrite the existed file. 2785 * false, go to fail. 2786 * 2787 * @type { ?boolean } 2788 * @syscap SystemCapability.Request.FileTransferAgent 2789 * @since 10 2790 */ 2791 /** 2792 * The solution choice when path already exists during download. 2793 * The default is false. 2794 * Currently support: 2795 * true, rewrite the existed file. 2796 * false, go to fail. 2797 * 2798 * @type { ?boolean } 2799 * @syscap SystemCapability.Request.FileTransferAgent 2800 * @crossplatform 2801 * @atomicservice 2802 * @since 11 2803 */ 2804 overwrite?: boolean; 2805 /** 2806 * The HTTP standard method for upload or download: GET/POST/PUT. 2807 * Case insensitive. 2808 * For upload, use PUT/POST, the default is PUT. 2809 * For download, use GET/POST, the default is GET. 2810 * 2811 * @type { ?string } 2812 * @syscap SystemCapability.Request.FileTransferAgent 2813 * @since 10 2814 */ 2815 /** 2816 * The HTTP standard method for upload or download: GET/POST/PUT. 2817 * Case insensitive. 2818 * For upload, use PUT/POST, the default is PUT. 2819 * For download, use GET/POST, the default is GET. 2820 * 2821 * @type { ?string } 2822 * @syscap SystemCapability.Request.FileTransferAgent 2823 * @crossplatform 2824 * @atomicservice 2825 * @since 11 2826 */ 2827 method?: string; 2828 /** 2829 * The HTTP headers. 2830 * For upload request, the `Content-Type` is forced to `multipart/form-data`. 2831 * For download request, the default `Content-Type` is `application/json`. 2832 * 2833 * @type { ?object } 2834 * @syscap SystemCapability.Request.FileTransferAgent 2835 * @since 10 2836 */ 2837 /** 2838 * The HTTP headers. 2839 * For upload request, the `Content-Type` is forced to `multipart/form-data`. 2840 * For download request, the default `Content-Type` is `application/json`. 2841 * 2842 * @type { ?object } 2843 * @syscap SystemCapability.Request.FileTransferAgent 2844 * @crossplatform 2845 * @atomicservice 2846 * @since 11 2847 */ 2848 headers?: object; 2849 /** 2850 * The arguments, it can be any text, uses json usually. 2851 * For download, it can be raw string, the default is empty string. 2852 * For upload, it can be form items, the default is a empty form. 2853 * there must be one `FileSpec` item at least or will be a parameter error. 2854 * 2855 * @type { ?(string | Array<FormItem>) } 2856 * @syscap SystemCapability.Request.FileTransferAgent 2857 * @since 10 2858 */ 2859 /** 2860 * The arguments, it can be any text, uses json usually. 2861 * For download, it can be raw string, the default is empty string. 2862 * For upload, it can be form items, the default is a empty form. 2863 * there must be one `FileSpec` item at least or will be a parameter error. 2864 * 2865 * @type { ?(string | Array<FormItem>) } 2866 * @syscap SystemCapability.Request.FileTransferAgent 2867 * @crossplatform 2868 * @atomicservice 2869 * @since 11 2870 */ 2871 data?: string | Array<FormItem>; 2872 /** 2873 * The path to save the downloaded file, the default is "./". 2874 * Currently support: 2875 * 1: relative path, like "./xxx/yyy/zzz.html", "xxx/yyy/zzz.html", under caller's cache folder. 2876 * 2: uri path, like "datashare://bundle/xxx/yyy/zzz.html", the data provider must allow the caller's access. 2877 * 2878 * @type { ?string } 2879 * @default ./ 2880 * @syscap SystemCapability.Request.FileTransferAgent 2881 * @since 10 2882 */ 2883 /** 2884 * The path to save the downloaded file, the default is "./". 2885 * Currently support: 2886 * 1: relative path, like "./xxx/yyy/zzz.html", "xxx/yyy/zzz.html", under caller's cache folder. 2887 * 2: uri path, like "datashare://bundle/xxx/yyy/zzz.html", the data provider must allow the caller's access. 2888 * 2889 * @type { ?string } 2890 * @default ./ 2891 * @syscap SystemCapability.Request.FileTransferAgent 2892 * @crossplatform 2893 * @atomicservice 2894 * @since 11 2895 */ 2896 saveas?: string; 2897 /** 2898 * The network. 2899 * 2900 * @type { ?Network } 2901 * @default Network.ANY 2902 * @syscap SystemCapability.Request.FileTransferAgent 2903 * @since 10 2904 */ 2905 /** 2906 * The network. 2907 * 2908 * @type { ?Network } 2909 * @default Network.ANY 2910 * @syscap SystemCapability.Request.FileTransferAgent 2911 * @crossplatform 2912 * @atomicservice 2913 * @since 11 2914 */ 2915 network?: Network; 2916 /** 2917 * Allows work in metered network or not. 2918 * The default is false. 2919 * 2920 * @type { ?boolean } 2921 * @default false 2922 * @syscap SystemCapability.Request.FileTransferAgent 2923 * @since 10 2924 */ 2925 /** 2926 * Allows work in metered network or not. 2927 * The default is false. 2928 * 2929 * @type { ?boolean } 2930 * @default false 2931 * @syscap SystemCapability.Request.FileTransferAgent 2932 * @crossplatform 2933 * @atomicservice 2934 * @since 11 2935 */ 2936 metered?: boolean; 2937 /** 2938 * Allows work in roaming network or not. 2939 * The default is true. 2940 * 2941 * @type { ?boolean } 2942 * @syscap SystemCapability.Request.FileTransferAgent 2943 * @since 10 2944 */ 2945 /** 2946 * Allows work in roaming network or not. 2947 * The default is true. 2948 * 2949 * @type { ?boolean } 2950 * @syscap SystemCapability.Request.FileTransferAgent 2951 * @crossplatform 2952 * @atomicservice 2953 * @since 11 2954 */ 2955 roaming?: boolean; 2956 /** 2957 * Enable automatic retry or not for the background task. 2958 * The frontend task is always fast-fail. 2959 * 2960 * @type { ?boolean } 2961 * @syscap SystemCapability.Request.FileTransferAgent 2962 * @since 10 2963 */ 2964 /** 2965 * Enable automatic retry or not for the background task. 2966 * The frontend task is always fast-fail. 2967 * 2968 * @type { ?boolean } 2969 * @syscap SystemCapability.Request.FileTransferAgent 2970 * @atomicservice 2971 * @since 11 2972 */ 2973 retry?: boolean; 2974 /** 2975 * Allows redirect or not. 2976 * The default is yes. 2977 * 2978 * @type { ?boolean } 2979 * @syscap SystemCapability.Request.FileTransferAgent 2980 * @since 10 2981 */ 2982 /** 2983 * Allows redirect or not. 2984 * The default is true. 2985 * 2986 * @type { ?boolean } 2987 * @syscap SystemCapability.Request.FileTransferAgent 2988 * @crossplatform 2989 * @atomicservice 2990 * @since 11 2991 */ 2992 redirect?: boolean; 2993 /** 2994 * The index of paths for a task. 2995 * Usually used for a continuous job. 2996 * The default is 0. 2997 * 2998 * @type { ?number } 2999 * @syscap SystemCapability.Request.FileTransferAgent 3000 * @since 10 3001 */ 3002 /** 3003 * The index of paths for a task. 3004 * Usually used for a continuous job. 3005 * The default is 0. 3006 * 3007 * @type { ?number } 3008 * @syscap SystemCapability.Request.FileTransferAgent 3009 * @crossplatform 3010 * @atomicservice 3011 * @since 11 3012 */ 3013 index?: number; 3014 /** 3015 * The start point of a file. 3016 * Usually used for a continuous job. 3017 * It will set the "Range" header in download. 3018 * It will start read at the point in upload. 3019 * The default is 0. 3020 * 3021 * @type { ?number } 3022 * @syscap SystemCapability.Request.FileTransferAgent 3023 * @since 10 3024 */ 3025 /** 3026 * The start point of a file. 3027 * Usually used for a continuous job. 3028 * It will set the "Range" header in download. 3029 * It will start read at the point in upload. 3030 * The default is 0. 3031 * 3032 * @type { ?number } 3033 * @syscap SystemCapability.Request.FileTransferAgent 3034 * @crossplatform 3035 * @atomicservice 3036 * @since 11 3037 */ 3038 begins?: number; 3039 /** 3040 * The end point of a file. 3041 * Usually used for a continuous job. 3042 * It will set The "Range" header in download. 3043 * It will end read at the point in upload. 3044 * The default is -1 indicating the end of the data for upload or download. 3045 * 3046 * @type { ?number } 3047 * @syscap SystemCapability.Request.FileTransferAgent 3048 * @since 10 3049 */ 3050 /** 3051 * The end point of a file. 3052 * Usually used for a continuous job. 3053 * It will set The "Range" header in download. 3054 * It will end read at the point in upload. 3055 * The default is -1 indicating the end of the data for upload or download. 3056 * 3057 * @type { ?number } 3058 * @syscap SystemCapability.Request.FileTransferAgent 3059 * @crossplatform 3060 * @atomicservice 3061 * @since 11 3062 */ 3063 ends?: number; 3064 /** 3065 * The policy of the progress notification for background task. 3066 * If false: only completed or failed notification, the default. 3067 * If true, emits every progress, completed or failed notifications. 3068 * 3069 * @type { ?boolean } 3070 * @syscap SystemCapability.Request.FileTransferAgent 3071 * @since 10 3072 */ 3073 /** 3074 * The policy of the progress notification for background task. 3075 * If false: only completed or failed notification, the default. 3076 * If true, emits every progress, completed or failed notifications. 3077 * 3078 * @type { ?boolean } 3079 * @syscap SystemCapability.Request.FileTransferAgent 3080 * @atomicservice 3081 * @since 11 3082 */ 3083 gauge?: boolean; 3084 /** 3085 * Breaks when fail to fetch filesize before upload/download or not. 3086 * Uses filesize for a precise gauge. 3087 * The default is not, set size as -1 indicating the case. 3088 * 3089 * @type { ?boolean } 3090 * @syscap SystemCapability.Request.FileTransferAgent 3091 * @since 10 3092 */ 3093 /** 3094 * Breaks when fail to fetch filesize before upload/download or not. 3095 * Uses filesize for a precise gauge. 3096 * The default is false, set size as -1 indicating the case. 3097 * 3098 * @type { ?boolean } 3099 * @syscap SystemCapability.Request.FileTransferAgent 3100 * @crossplatform 3101 * @atomicservice 3102 * @since 11 3103 */ 3104 precise?: boolean; 3105 /** 3106 * For in-application layer isolation. 3107 * If given: 3108 * the minimum is 8 bytes. 3109 * the maximum is 2048 bytes. 3110 * Creates a task with token, then must provide it during normal query. 3111 * So saves the token carefully, it can not be retrieved by query. 3112 * Or leave it empty. 3113 * 3114 * @type { ?string } 3115 * @syscap SystemCapability.Request.FileTransferAgent 3116 * @since 10 3117 */ 3118 /** 3119 * For in-application layer isolation. 3120 * If given: 3121 * the minimum is 8 bytes. 3122 * the maximum is 2048 bytes. 3123 * Creates a task with token, then must provide it during normal query. 3124 * So saves the token carefully, it can not be retrieved by query. 3125 * Or leave it empty. 3126 * 3127 * @type { ?string } 3128 * @syscap SystemCapability.Request.FileTransferAgent 3129 * @crossplatform 3130 * @atomicservice 3131 * @since 11 3132 */ 3133 token?: string; 3134 /** 3135 * The priority of this task. 3136 * Front-end tasks have higher priority than back-end tasks. 3137 * In tasks of the same mode, the smaller the number, the higher the priority. 3138 * The default is 0. 3139 * 3140 * @type { ?number } 3141 * @syscap SystemCapability.Request.FileTransferAgent 3142 * @since 11 3143 */ 3144 priority?: number; 3145 /** 3146 * The extras for the configuration. 3147 * 3148 * @type { ?object } 3149 * @syscap SystemCapability.Request.FileTransferAgent 3150 * @since 10 3151 */ 3152 /** 3153 * The extras for the configuration. 3154 * 3155 * @type { ?object } 3156 * @syscap SystemCapability.Request.FileTransferAgent 3157 * @crossplatform 3158 * @atomicservice 3159 * @since 11 3160 */ 3161 extras?: object; 3162 } 3163 3164 /** 3165 * Indicate the current state of the task. 3166 * 3167 * @enum { number } State 3168 * @syscap SystemCapability.Request.FileTransferAgent 3169 * @since 10 3170 */ 3171 /** 3172 * Indicate the current state of the task. 3173 * 3174 * @enum { number } State 3175 * @syscap SystemCapability.Request.FileTransferAgent 3176 * @crossplatform 3177 * @atomicservice 3178 * @since 11 3179 */ 3180 enum State { 3181 /** 3182 * Indicates a task created by `new Task(Config)`. 3183 * 3184 * @syscap SystemCapability.Request.FileTransferAgent 3185 * @since 10 3186 */ 3187 /** 3188 * Indicates a task created by `new Task(Config)`. 3189 * 3190 * @syscap SystemCapability.Request.FileTransferAgent 3191 * @crossplatform 3192 * @atomicservice 3193 * @since 11 3194 */ 3195 INITIALIZED = 0x00, 3196 /** 3197 * Indicates a task lack of resources or conditions to run or retry. 3198 * 3199 * @syscap SystemCapability.Request.FileTransferAgent 3200 * @since 10 3201 */ 3202 /** 3203 * Indicates a task lack of resources or conditions to run or retry. 3204 * 3205 * @syscap SystemCapability.Request.FileTransferAgent 3206 * @crossplatform 3207 * @atomicservice 3208 * @since 11 3209 */ 3210 WAITING = 0x10, 3211 /** 3212 * Indicates a task in processing now. 3213 * 3214 * @syscap SystemCapability.Request.FileTransferAgent 3215 * @since 10 3216 */ 3217 /** 3218 * Indicates a task in processing now. 3219 * 3220 * @syscap SystemCapability.Request.FileTransferAgent 3221 * @crossplatform 3222 * @atomicservice 3223 * @since 11 3224 */ 3225 RUNNING = 0x20, 3226 /** 3227 * Indicates a task failed once at least and in processing again now. 3228 * 3229 * @syscap SystemCapability.Request.FileTransferAgent 3230 * @since 10 3231 */ 3232 /** 3233 * Indicates a task failed once at least and in processing again now. 3234 * 3235 * @syscap SystemCapability.Request.FileTransferAgent 3236 * @crossplatform 3237 * @atomicservice 3238 * @since 11 3239 */ 3240 RETRYING = 0x21, 3241 /** 3242 * Indicates a paused task which tends to be resumed for continuous work. 3243 * 3244 * @syscap SystemCapability.Request.FileTransferAgent 3245 * @since 10 3246 */ 3247 /** 3248 * Indicates a paused task which tends to be resumed for continuous work. 3249 * 3250 * @syscap SystemCapability.Request.FileTransferAgent 3251 * @crossplatform 3252 * @atomicservice 3253 * @since 11 3254 */ 3255 PAUSED = 0x30, 3256 /** 3257 * Indicates a stopped task which must be started again. 3258 * 3259 * @syscap SystemCapability.Request.FileTransferAgent 3260 * @since 10 3261 */ 3262 /** 3263 * Indicates a stopped task which must be started again. 3264 * 3265 * @syscap SystemCapability.Request.FileTransferAgent 3266 * @crossplatform 3267 * @atomicservice 3268 * @since 11 3269 */ 3270 STOPPED = 0x31, 3271 /** 3272 * Indicates a completed task which finish its data transfer. 3273 * 3274 * @syscap SystemCapability.Request.FileTransferAgent 3275 * @since 10 3276 */ 3277 /** 3278 * Indicates a completed task which finish its data transfer. 3279 * 3280 * @syscap SystemCapability.Request.FileTransferAgent 3281 * @crossplatform 3282 * @atomicservice 3283 * @since 11 3284 */ 3285 COMPLETED = 0x40, 3286 /** 3287 * Indicates a failed task which interrupted by some error. 3288 * 3289 * @syscap SystemCapability.Request.FileTransferAgent 3290 * @since 10 3291 */ 3292 /** 3293 * Indicates a failed task which interrupted by some error. 3294 * 3295 * @syscap SystemCapability.Request.FileTransferAgent 3296 * @crossplatform 3297 * @atomicservice 3298 * @since 11 3299 */ 3300 FAILED = 0x41, 3301 /** 3302 * Indicates a removed task which can not be processed again. 3303 * 3304 * @syscap SystemCapability.Request.FileTransferAgent 3305 * @since 10 3306 */ 3307 /** 3308 * Indicates a removed task which can not be processed again. 3309 * 3310 * @syscap SystemCapability.Request.FileTransferAgent 3311 * @crossplatform 3312 * @atomicservice 3313 * @since 11 3314 */ 3315 REMOVED = 0x50 3316 } 3317 3318 /** 3319 * The progress data structure. 3320 * Upload allows multiple files per upload task. 3321 * Only one file in a download task. 3322 * So using a unified data structure for progress. 3323 * Generally: 3324 * 1: sum(sizes) is total files size of the task. 3325 * 2: float(processed)/sizes[counter] is the progress for the current processing file. 3326 * 3: float(sum(sizes[:index])+processed)/sum(sizes) is the summary progress for a task. 3327 * If fetch file size in failure, the size of the file in sizes will be set as -1. 3328 * 3329 * @typedef Progress 3330 * @syscap SystemCapability.Request.FileTransferAgent 3331 * @since 10 3332 */ 3333 /** 3334 * The progress data structure. 3335 * Upload allows multiple files per upload task. 3336 * Only one file in a download task. 3337 * So using a unified data structure for progress. 3338 * Generally: 3339 * 1: sum(sizes) is total files size of the task. 3340 * 2: float(processed)/sizes[counter] is the progress for the current processing file. 3341 * 3: float(sum(sizes[:index])+processed)/sum(sizes) is the summary progress for a task. 3342 * If fetch file size in failure, the size of the file in sizes will be set as -1. 3343 * 3344 * @typedef Progress 3345 * @syscap SystemCapability.Request.FileTransferAgent 3346 * @crossplatform 3347 * @atomicservice 3348 * @since 11 3349 */ 3350 interface Progress { 3351 /** 3352 * The current state of the task. 3353 * 3354 * @type { State } 3355 * @readonly 3356 * @syscap SystemCapability.Request.FileTransferAgent 3357 * @since 10 3358 */ 3359 /** 3360 * The current state of the task. 3361 * 3362 * @type { State } 3363 * @readonly 3364 * @syscap SystemCapability.Request.FileTransferAgent 3365 * @crossplatform 3366 * @atomicservice 3367 * @since 11 3368 */ 3369 readonly state: State; 3370 /** 3371 * The current processing file index in a task. 3372 * 3373 * @type { number } 3374 * @readonly 3375 * @syscap SystemCapability.Request.FileTransferAgent 3376 * @since 10 3377 */ 3378 /** 3379 * The current processing file index in a task. 3380 * 3381 * @type { number } 3382 * @readonly 3383 * @syscap SystemCapability.Request.FileTransferAgent 3384 * @crossplatform 3385 * @atomicservice 3386 * @since 11 3387 */ 3388 readonly index: number; 3389 /** 3390 * The processed data size for the current file in a task. 3391 * 3392 * @type { number } 3393 * @readonly 3394 * @syscap SystemCapability.Request.FileTransferAgent 3395 * @since 10 3396 */ 3397 /** 3398 * The processed data size for the current file in a task. 3399 * 3400 * @type { number } 3401 * @readonly 3402 * @syscap SystemCapability.Request.FileTransferAgent 3403 * @crossplatform 3404 * @atomicservice 3405 * @since 11 3406 */ 3407 readonly processed: number; 3408 /** 3409 * The sizes of files in a task. 3410 * 3411 * @type { Array<number> } 3412 * @readonly 3413 * @syscap SystemCapability.Request.FileTransferAgent 3414 * @since 10 3415 */ 3416 /** 3417 * The sizes of files in a task. 3418 * 3419 * @type { Array<number> } 3420 * @readonly 3421 * @syscap SystemCapability.Request.FileTransferAgent 3422 * @crossplatform 3423 * @atomicservice 3424 * @since 11 3425 */ 3426 readonly sizes: Array<number>; 3427 /** 3428 * The extras for an interaction. 3429 * Such as headers and body of response from server. 3430 * But when the Content-Disposition header responded, the body will be into the uri of its attachment only, the body here is empty. 3431 * {"headers": {"key": v}, "body": "contents"}. 3432 * 3433 * @type { ?object } 3434 * @readonly 3435 * @syscap SystemCapability.Request.FileTransferAgent 3436 * @since 10 3437 */ 3438 /** 3439 * The extras for an interaction. 3440 * Such as headers and body of response from server. 3441 * But when the Content-Disposition header responded, the body will be into the uri of its attachment only, the body here is empty. 3442 * {"headers": {"key": v}, "body": "contents"}. 3443 * The "body" field is not supported in cross-platform scenarios. 3444 * 3445 * @type { ?object } 3446 * @readonly 3447 * @syscap SystemCapability.Request.FileTransferAgent 3448 * @crossplatform 3449 * @atomicservice 3450 * @since 11 3451 */ 3452 readonly extras?: object; 3453 } 3454 3455 /** 3456 * Indicates the reason for the failure. 3457 * 3458 * @enum { number } 3459 * @syscap SystemCapability.Request.FileTransferAgent 3460 * @since 10 3461 */ 3462 /** 3463 * Indicates the reason for the failure. 3464 * 3465 * @enum { number } 3466 * @syscap SystemCapability.Request.FileTransferAgent 3467 * @crossplatform 3468 * @atomicservice 3469 * @since 11 3470 */ 3471 enum Faults { 3472 /** 3473 * Indicates others failure. 3474 * 3475 * @syscap SystemCapability.Request.FileTransferAgent 3476 * @since 10 3477 */ 3478 /** 3479 * Indicates others failure. 3480 * 3481 * @syscap SystemCapability.Request.FileTransferAgent 3482 * @crossplatform 3483 * @atomicservice 3484 * @since 11 3485 */ 3486 OTHERS = 0xFF, 3487 /** 3488 * Indicates network disconnection. 3489 * 3490 * @syscap SystemCapability.Request.FileTransferAgent 3491 * @since 10 3492 */ 3493 /** 3494 * Indicates network disconnection. 3495 * 3496 * @syscap SystemCapability.Request.FileTransferAgent 3497 * @crossplatform 3498 * @atomicservice 3499 * @since 11 3500 */ 3501 DISCONNECTED = 0x00, 3502 /** 3503 * Indicates task timeout. 3504 * 3505 * @syscap SystemCapability.Request.FileTransferAgent 3506 * @since 10 3507 */ 3508 /** 3509 * Indicates task timeout. 3510 * 3511 * @syscap SystemCapability.Request.FileTransferAgent 3512 * @crossplatform 3513 * @atomicservice 3514 * @since 11 3515 */ 3516 TIMEOUT = 0x10, 3517 /** 3518 * Indicates protocol error, such as 5xx response from server. 3519 * 3520 * @syscap SystemCapability.Request.FileTransferAgent 3521 * @since 10 3522 */ 3523 /** 3524 * Indicates protocol error, such as 5xx response from server. 3525 * 3526 * @syscap SystemCapability.Request.FileTransferAgent 3527 * @crossplatform 3528 * @atomicservice 3529 * @since 11 3530 */ 3531 PROTOCOL = 0x20, 3532 /** 3533 * Indicates filesystem io error, such as open/seek/read/write/close. 3534 * 3535 * @syscap SystemCapability.Request.FileTransferAgent 3536 * @since 10 3537 */ 3538 /** 3539 * Indicates filesystem io error, such as open/seek/read/write/close. 3540 * 3541 * @syscap SystemCapability.Request.FileTransferAgent 3542 * @crossplatform 3543 * @atomicservice 3544 * @since 11 3545 */ 3546 FSIO = 0x40 3547 } 3548 3549 /** 3550 * The filter data structure. 3551 * Used for search, given fields works as **LOGICAL AND**. 3552 * Invalid value may cause a parameter error. 3553 * 3554 * @typedef Filter 3555 * @syscap SystemCapability.Request.FileTransferAgent 3556 * @since 10 3557 */ 3558 /** 3559 * The filter data structure. 3560 * Used for search, given fields works as **LOGICAL AND**. 3561 * Invalid value may cause a parameter error. 3562 * 3563 * @typedef Filter 3564 * @syscap SystemCapability.Request.FileTransferAgent 3565 * @crossplatform 3566 * @since 11 3567 */ 3568 interface Filter { 3569 /** 3570 * Specify the package name of an application. 3571 * Only for advanced search, common search will be fixed to the caller. 3572 * A "*" means any bundle. 3573 * 3574 * @type { ?string } 3575 * @syscap SystemCapability.Request.FileTransferAgent 3576 * @systemapi Hide this for inner system use. 3577 * @since 10 3578 */ 3579 bundle?: string; 3580 /** 3581 * Specify the end Unix timestamp. 3582 * The default is the moment of calling. 3583 * 3584 * @type { ?number } 3585 * @syscap SystemCapability.Request.FileTransferAgent 3586 * @since 10 3587 */ 3588 /** 3589 * Specify the end Unix timestamp. 3590 * The default is the moment of calling. 3591 * 3592 * @type { ?number } 3593 * @syscap SystemCapability.Request.FileTransferAgent 3594 * @crossplatform 3595 * @since 11 3596 */ 3597 before?: number; 3598 /** 3599 * Specify the start Unix timestamp. 3600 * The default is "`before` - 24 hours". 3601 * 3602 * @type { ?number } 3603 * @syscap SystemCapability.Request.FileTransferAgent 3604 * @since 10 3605 */ 3606 /** 3607 * Specify the start Unix timestamp. 3608 * The default is "`before` - 24 hours". 3609 * 3610 * @type { ?number } 3611 * @syscap SystemCapability.Request.FileTransferAgent 3612 * @crossplatform 3613 * @since 11 3614 */ 3615 after?: number; 3616 /** 3617 * Specify the state of tasks. 3618 * The default is any state. 3619 * 3620 * @type { ?State } 3621 * @syscap SystemCapability.Request.FileTransferAgent 3622 * @since 10 3623 */ 3624 /** 3625 * Specify the state of tasks. 3626 * The default is any state. 3627 * 3628 * @type { ?State } 3629 * @syscap SystemCapability.Request.FileTransferAgent 3630 * @crossplatform 3631 * @since 11 3632 */ 3633 state?: State; 3634 /** 3635 * Specify the action of tasks, "upload" or "download", case insensitive. 3636 * The default is upload and download. 3637 * 3638 * @type { ?Action } 3639 * @syscap SystemCapability.Request.FileTransferAgent 3640 * @since 10 3641 */ 3642 /** 3643 * Specify the action of tasks, "upload" or "download", case insensitive. 3644 * The default is upload and download. 3645 * 3646 * @type { ?Action } 3647 * @syscap SystemCapability.Request.FileTransferAgent 3648 * @crossplatform 3649 * @since 11 3650 */ 3651 action?: Action; 3652 /** 3653 * Specify task's mode. 3654 * The default is frontend and background. 3655 * 3656 * @type { ?Mode } 3657 * @syscap SystemCapability.Request.FileTransferAgent 3658 * @since 10 3659 */ 3660 /** 3661 * Specify task's mode. 3662 * The default is FOREGROUND and BACKGROUND. 3663 * 3664 * @type { ?Mode } 3665 * @syscap SystemCapability.Request.FileTransferAgent 3666 * @crossplatform 3667 * @since 11 3668 */ 3669 mode?: Mode; 3670 } 3671 3672 /** 3673 * The task information data structure for query results. 3674 * Provides common query and advanced query, visible range of fields is different. 3675 * 3676 * @typedef TaskInfo 3677 * @syscap SystemCapability.Request.FileTransferAgent 3678 * @since 10 3679 */ 3680 /** 3681 * The task information data structure for query results. 3682 * Provides common query and advanced query, visible range of fields is different. 3683 * 3684 * @typedef TaskInfo 3685 * @syscap SystemCapability.Request.FileTransferAgent 3686 * @crossplatform 3687 * @since 11 3688 */ 3689 interface TaskInfo { 3690 /** 3691 * The UID of an application. 3692 * For system query only. 3693 * 3694 * @type { ?string } 3695 * @readonly 3696 * @syscap SystemCapability.Request.FileTransferAgent 3697 * @systemapi Hide this for inner system use. 3698 * @since 10 3699 */ 3700 readonly uid?: string; 3701 /** 3702 * The bundle name. 3703 * For system query only. 3704 * 3705 * @type { ?string } 3706 * @readonly 3707 * @syscap SystemCapability.Request.FileTransferAgent 3708 * @systemapi Hide this for inner system use. 3709 * @since 10 3710 */ 3711 readonly bundle?: string; 3712 /** 3713 * The path to save the downloaded file. 3714 * 3715 * @type { ?string } 3716 * @syscap SystemCapability.Request.FileTransferAgent 3717 * @since 10 3718 */ 3719 /** 3720 * The path to save the downloaded file. 3721 * 3722 * @type { ?string } 3723 * @readonly 3724 * @syscap SystemCapability.Request.FileTransferAgent 3725 * @crossplatform 3726 * @since 11 3727 */ 3728 readonly saveas?: string; 3729 /** 3730 * The url of a task. 3731 * For `${ show }` and `${ touch }`. 3732 * It is empty string in `${ query }`. 3733 * 3734 * @type { ?string } 3735 * @readonly 3736 * @syscap SystemCapability.Request.FileTransferAgent 3737 * @since 10 3738 */ 3739 /** 3740 * The url of a task. 3741 * For `${ show }` and `${ touch }`. 3742 * 3743 * @type { ?string } 3744 * @readonly 3745 * @syscap SystemCapability.Request.FileTransferAgent 3746 * @crossplatform 3747 * @since 11 3748 */ 3749 readonly url?: string; 3750 /** 3751 * The arguments. 3752 * For `${ show }` and `${ touch }`. 3753 * It is empty string in `${ query }`. 3754 * 3755 * @type { ?(string | Array<FormItem>) } 3756 * @syscap SystemCapability.Request.FileTransferAgent 3757 * @since 10 3758 */ 3759 /** 3760 * The arguments. 3761 * For `${ show }` and `${ touch }`. 3762 * 3763 * @type { ?(string | Array<FormItem>) } 3764 * @readonly 3765 * @syscap SystemCapability.Request.FileTransferAgent 3766 * @crossplatform 3767 * @since 11 3768 */ 3769 readonly data?: string | Array<FormItem>; 3770 /** 3771 * The task id. 3772 * 3773 * @type { string } 3774 * @readonly 3775 * @syscap SystemCapability.Request.FileTransferAgent 3776 * @since 10 3777 */ 3778 /** 3779 * The task id. 3780 * 3781 * @type { string } 3782 * @readonly 3783 * @syscap SystemCapability.Request.FileTransferAgent 3784 * @crossplatform 3785 * @since 11 3786 */ 3787 readonly tid: string; 3788 /** 3789 * The task title. 3790 * 3791 * @type { string } 3792 * @readonly 3793 * @syscap SystemCapability.Request.FileTransferAgent 3794 * @since 10 3795 */ 3796 /** 3797 * The task title. 3798 * 3799 * @type { string } 3800 * @readonly 3801 * @syscap SystemCapability.Request.FileTransferAgent 3802 * @crossplatform 3803 * @since 11 3804 */ 3805 readonly title: string; 3806 /** 3807 * The task details. 3808 * 3809 * @type { string } 3810 * @readonly 3811 * @syscap SystemCapability.Request.FileTransferAgent 3812 * @since 10 3813 */ 3814 /** 3815 * The task details. 3816 * 3817 * @type { string } 3818 * @readonly 3819 * @syscap SystemCapability.Request.FileTransferAgent 3820 * @crossplatform 3821 * @since 11 3822 */ 3823 readonly description: string; 3824 /** 3825 * The task action. 3826 * 3827 * @type { Action } 3828 * @readonly 3829 * @syscap SystemCapability.Request.FileTransferAgent 3830 * @since 10 3831 */ 3832 /** 3833 * The task action. 3834 * 3835 * @type { Action } 3836 * @readonly 3837 * @syscap SystemCapability.Request.FileTransferAgent 3838 * @crossplatform 3839 * @since 11 3840 */ 3841 readonly action: Action; 3842 /** 3843 * Specify task mode. 3844 * The default is frontend and background. 3845 * 3846 * @type { Mode } 3847 * @syscap SystemCapability.Request.FileTransferAgent 3848 * @since 10 3849 */ 3850 /** 3851 * Specify task mode. 3852 * The default is frontend. 3853 * 3854 * @type { Mode } 3855 * @readonly 3856 * @syscap SystemCapability.Request.FileTransferAgent 3857 * @crossplatform 3858 * @since 11 3859 */ 3860 readonly mode: Mode; 3861 /** 3862 * The priority of this task. 3863 * Front-end tasks have higher priority than back-end tasks. 3864 * In tasks of the same mode, the smaller the number, the higher the priority. 3865 * The default is 0. 3866 * 3867 * @type { number } 3868 * @readonly 3869 * @syscap SystemCapability.Request.FileTransferAgent 3870 * @since 11 3871 */ 3872 readonly priority: number; 3873 /** 3874 * The MIME type in the configuration of the task. 3875 * 3876 * @type { string } 3877 * @readonly 3878 * @syscap SystemCapability.Request.FileTransferAgent 3879 * @since 10 3880 */ 3881 /** 3882 * The MIME type in the configuration of the task. 3883 * 3884 * @type { string } 3885 * @readonly 3886 * @syscap SystemCapability.Request.FileTransferAgent 3887 * @crossplatform 3888 * @since 11 3889 */ 3890 readonly mimeType: string; 3891 /** 3892 * An instance of `Progress` for a task. 3893 * 3894 * @type { Progress } 3895 * @readonly 3896 * @syscap SystemCapability.Request.FileTransferAgent 3897 * @since 10 3898 */ 3899 /** 3900 * An instance of `Progress` for a task. 3901 * 3902 * @type { Progress } 3903 * @readonly 3904 * @syscap SystemCapability.Request.FileTransferAgent 3905 * @crossplatform 3906 * @since 11 3907 */ 3908 readonly progress: Progress; 3909 /** 3910 * The progress notification policy of a background task. 3911 * 3912 * @type { boolean } 3913 * @readonly 3914 * @syscap SystemCapability.Request.FileTransferAgent 3915 * @since 10 3916 */ 3917 readonly gauge: boolean; 3918 /** 3919 * The creating date and time of a task in Unix timestamp. 3920 * It is generated by system of current device. 3921 * 3922 * @type { number } 3923 * @readonly 3924 * @syscap SystemCapability.Request.FileTransferAgent 3925 * @since 10 3926 */ 3927 /** 3928 * The creating date and time of a task in Unix timestamp. 3929 * It is generated by system of current device. 3930 * 3931 * @type { number } 3932 * @readonly 3933 * @syscap SystemCapability.Request.FileTransferAgent 3934 * @crossplatform 3935 * @since 11 3936 */ 3937 readonly ctime: number; 3938 /** 3939 * The modified date and time of a task in Unix timestamp. 3940 * It is generated by system of current device. 3941 * 3942 * @type { number } 3943 * @readonly 3944 * @syscap SystemCapability.Request.FileTransferAgent 3945 * @since 10 3946 */ 3947 /** 3948 * The modified date and time of a task in Unix timestamp. 3949 * It is generated by system of current device. 3950 * 3951 * @type { number } 3952 * @readonly 3953 * @syscap SystemCapability.Request.FileTransferAgent 3954 * @crossplatform 3955 * @since 11 3956 */ 3957 readonly mtime: number; 3958 /** 3959 * The retry switch of a task. 3960 * Just for background, frontend always disabled. 3961 * 3962 * @type { boolean } 3963 * @readonly 3964 * @syscap SystemCapability.Request.FileTransferAgent 3965 * @since 10 3966 */ 3967 readonly retry: boolean; 3968 /** 3969 * The tried times of a task. 3970 * 3971 * @type { number } 3972 * @readonly 3973 * @syscap SystemCapability.Request.FileTransferAgent 3974 * @since 10 3975 */ 3976 readonly tries: number; 3977 /** 3978 * The faults case of a task. 3979 * 3980 * @type { Faults } 3981 * @readonly 3982 * @syscap SystemCapability.Request.FileTransferAgent 3983 * @since 10 3984 */ 3985 /** 3986 * The faults case of a task. 3987 * 3988 * @type { Faults } 3989 * @readonly 3990 * @syscap SystemCapability.Request.FileTransferAgent 3991 * @crossplatform 3992 * @since 11 3993 */ 3994 readonly faults: Faults; 3995 /** 3996 * The reason of a waiting/failed/stopped/paused task. 3997 * 3998 * @type { string } 3999 * @readonly 4000 * @syscap SystemCapability.Request.FileTransferAgent 4001 * @since 10 4002 */ 4003 /** 4004 * The reason of a waiting/failed/stopped/paused task. 4005 * 4006 * @type { string } 4007 * @readonly 4008 * @syscap SystemCapability.Request.FileTransferAgent 4009 * @crossplatform 4010 * @since 11 4011 */ 4012 readonly reason: string; 4013 /** 4014 * The extras of a task. 4015 * For background, the last response from server. 4016 * For frontend, nothing now. 4017 * 4018 * @type { ?object } 4019 * @readonly 4020 * @syscap SystemCapability.Request.FileTransferAgent 4021 * @since 10 4022 */ 4023 /** 4024 * The extras of a task. 4025 * For frontend, nothing now. 4026 * 4027 * @type { ?object } 4028 * @readonly 4029 * @syscap SystemCapability.Request.FileTransferAgent 4030 * @crossplatform 4031 * @since 11 4032 */ 4033 readonly extras?: object; 4034 } 4035 4036 /** 4037 * The task entry. 4038 * New task' status is "initialized" and enqueue. 4039 * Can `start` a initialized task. 4040 * Can `pause` a waiting/running/retrying background task. 4041 * Can `resume` a paused background task. 4042 * Can `stop` a running/waiting/retrying task and dequeue it. 4043 * 4044 * @typedef Task 4045 * @syscap SystemCapability.Request.FileTransferAgent 4046 * @since 10 4047 */ 4048 /** 4049 * The task entry. 4050 * New task' status is "initialized" and enqueue. 4051 * Can `start` a initialized task. 4052 * Can `pause` a waiting/running/retrying background task. 4053 * Can `resume` a paused background task. 4054 * Can `stop` a running/waiting/retrying task and dequeue it. 4055 * 4056 * @typedef Task 4057 * @syscap SystemCapability.Request.FileTransferAgent 4058 * @crossplatform 4059 * @atomicservice 4060 * @since 11 4061 */ 4062 interface Task { 4063 /** 4064 * The task id, unique on system. 4065 * Generated automatically by system. 4066 * 4067 * @type { string } 4068 * @readonly 4069 * @syscap SystemCapability.Request.FileTransferAgent 4070 * @since 10 4071 */ 4072 /** 4073 * The task id, unique on system. 4074 * Generated automatically by system. 4075 * 4076 * @type { string } 4077 * @readonly 4078 * @syscap SystemCapability.Request.FileTransferAgent 4079 * @crossplatform 4080 * @atomicservice 4081 * @since 11 4082 */ 4083 readonly tid: string; 4084 /** 4085 * The configurations for the task. 4086 * 4087 * @type { Config } 4088 * @syscap SystemCapability.Request.FileTransferAgent 4089 * @since 10 4090 */ 4091 /** 4092 * The configurations for the task. 4093 * 4094 * @type { Config } 4095 * @syscap SystemCapability.Request.FileTransferAgent 4096 * @crossplatform 4097 * @atomicservice 4098 * @since 11 4099 */ 4100 config: Config; 4101 /** 4102 * Enable the specified callback for a frontend task. 4103 * 4104 * @param { 'progress' } event event types. 4105 * @param { function } callback callback function with a `Progress` argument. 4106 * @throws { BusinessError } 401 - Parameter error. 4107 * @throws { BusinessError } 21900005 - task mode error. 4108 * @syscap SystemCapability.Request.FileTransferAgent 4109 * @since 10 4110 */ 4111 /** 4112 * Enables the specified callback. 4113 * 4114 * @param { 'progress' } event - event types. 4115 * @param { function } callback - callback function with a `Progress` argument. 4116 * @throws { BusinessError } 401 - Parameter error. 4117 * @syscap SystemCapability.Request.FileTransferAgent 4118 * @crossplatform 4119 * @atomicservice 4120 * @since 11 4121 */ 4122 on(event: 'progress', callback: (progress: Progress) => void): void; 4123 /** 4124 * Disable the specified callback for a frontend task. 4125 * 4126 * @param { 'progress' } event event types. 4127 * @param { function } callback callback function with a `Progress` argument. 4128 * @throws { BusinessError } 401 - Parameter error. 4129 * @throws { BusinessError } 21900005 - task mode error. 4130 * @syscap SystemCapability.Request.FileTransferAgent 4131 * @since 10 4132 */ 4133 /** 4134 * Disables the specified callback. 4135 * 4136 * @param { 'progress' } event - event types. 4137 * @param { function } callback - callback function with a `Progress` argument. 4138 * @throws { BusinessError } 401 - Parameter error. 4139 * @syscap SystemCapability.Request.FileTransferAgent 4140 * @crossplatform 4141 * @atomicservice 4142 * @since 11 4143 */ 4144 off(event: 'progress', callback?: (progress: Progress) => void): void; 4145 /** 4146 * Enable the specified callback for a frontend task. 4147 * 4148 * @param { 'completed' } event event types. 4149 * @param { function } callback callback function with a `Progress` argument. 4150 * @throws { BusinessError } 401 - Parameter error. 4151 * @throws { BusinessError } 21900005 - task mode error. 4152 * @syscap SystemCapability.Request.FileTransferAgent 4153 * @since 10 4154 */ 4155 /** 4156 * Enables the specified callback. 4157 * 4158 * @param { 'completed' } event - event types. 4159 * @param { function } callback - callback function with a `Progress` argument. 4160 * @throws { BusinessError } 401 - Parameter error. 4161 * @syscap SystemCapability.Request.FileTransferAgent 4162 * @crossplatform 4163 * @atomicservice 4164 * @since 11 4165 */ 4166 on(event: 'completed', callback: (progress: Progress) => void): void; 4167 /** 4168 * Disable the specified callback for a frontend task. 4169 * 4170 * @param { 'completed' } event event types. 4171 * @param { function } callback callback function with a `Progress` argument. 4172 * @throws { BusinessError } 401 - Parameter error. 4173 * @throws { BusinessError } 21900005 - task mode error. 4174 * @syscap SystemCapability.Request.FileTransferAgent 4175 * @since 10 4176 */ 4177 /** 4178 * Disables the specified callback. 4179 * 4180 * @param { 'completed' } event - event types. 4181 * @param { function } callback - callback function with a `Progress` argument. 4182 * @throws { BusinessError } 401 - Parameter error. 4183 * @syscap SystemCapability.Request.FileTransferAgent 4184 * @crossplatform 4185 * @atomicservice 4186 * @since 11 4187 */ 4188 off(event: 'completed', callback?: (progress: Progress) => void): void; 4189 /** 4190 * Enable the specified callback for a frontend task. 4191 * 4192 * @param { 'failed' } event event types. 4193 * @param { function } callback callback function with a `Progress` argument. 4194 * @throws { BusinessError } 401 - Parameter error. 4195 * @throws { BusinessError } 21900005 - task mode error. 4196 * @syscap SystemCapability.Request.FileTransferAgent 4197 * @since 10 4198 */ 4199 /** 4200 * Enables the specified callback. 4201 * 4202 * @param { 'failed' } event - event types. 4203 * @param { function } callback - callback function with a `Progress` argument. 4204 * @throws { BusinessError } 401 - Parameter error. 4205 * @syscap SystemCapability.Request.FileTransferAgent 4206 * @crossplatform 4207 * @atomicservice 4208 * @since 11 4209 */ 4210 on(event: 'failed', callback: (progress: Progress) => void): void; 4211 /** 4212 * Disable the specified callback for a frontend task. 4213 * 4214 * @param { 'failed' } event event types. 4215 * @param { function } callback callback function with a `Progress` argument. 4216 * @throws { BusinessError } 401 - Parameter error. 4217 * @throws { BusinessError } 21900005 - task mode error. 4218 * @syscap SystemCapability.Request.FileTransferAgent 4219 * @since 10 4220 */ 4221 /** 4222 * Disables the specified callback. 4223 * 4224 * @param { 'failed' } event - event types. 4225 * @param { function } callback - callback function with a `Progress` argument. 4226 * @throws { BusinessError } 401 - Parameter error. 4227 * @syscap SystemCapability.Request.FileTransferAgent 4228 * @crossplatform 4229 * @atomicservice 4230 * @since 11 4231 */ 4232 off(event: 'failed', callback?: (progress: Progress) => void): void; 4233 /** 4234 * Enables the specified callback. 4235 * 4236 * @param { 'pause' } event - event types. 4237 * @param { function } callback - callback function with a `Progress` argument. 4238 * @throws { BusinessError } 401 - Parameter error. 4239 * @syscap SystemCapability.Request.FileTransferAgent 4240 * @since 11 4241 */ 4242 on(event: 'pause', callback: (progress: Progress) => void): void; 4243 /** 4244 * Disables the specified callback. 4245 * 4246 * @param { 'pause' } event - event types. 4247 * @param { function } callback - callback function with a `Progress` argument. 4248 * @throws { BusinessError } 401 - Parameter error. 4249 * @syscap SystemCapability.Request.FileTransferAgent 4250 * @since 11 4251 */ 4252 off(event: 'pause', callback?: (progress: Progress) => void): void; 4253 /** 4254 * Enables the specified callback. 4255 * 4256 * @param { 'resume' } event - event types. 4257 * @param { function } callback - callback function with a `Progress` argument. 4258 * @throws { BusinessError } 401 - Parameter error. 4259 * @syscap SystemCapability.Request.FileTransferAgent 4260 * @since 11 4261 */ 4262 on(event: 'resume', callback: (progress: Progress) => void): void; 4263 /** 4264 * Disables the specified callback. 4265 * 4266 * @param { 'resume' } event - event types. 4267 * @param { function } callback - callback function with a `Progress` argument. 4268 * @throws { BusinessError } 401 - Parameter error. 4269 * @syscap SystemCapability.Request.FileTransferAgent 4270 * @since 11 4271 */ 4272 off(event: 'resume', callback?: (progress: Progress) => void): void; 4273 /** 4274 * Enables the specified callback. 4275 * 4276 * @param { 'remove' } event - event types. 4277 * @param { function } callback - callback function with a `Progress` argument. 4278 * @throws { BusinessError } 401 - Parameter error. 4279 * @syscap SystemCapability.Request.FileTransferAgent 4280 * @since 11 4281 */ 4282 on(event: 'remove', callback: (progress: Progress) => void): void; 4283 /** 4284 * Disables the specified callback. 4285 * 4286 * @param { 'remove' } event - event types. 4287 * @param { function } callback - callback function with a `Progress` argument. 4288 * @throws { BusinessError } 401 - Parameter error. 4289 * @syscap SystemCapability.Request.FileTransferAgent 4290 * @since 11 4291 */ 4292 off(event: 'remove', callback?: (progress: Progress) => void): void; 4293 /** 4294 * Starts the task. 4295 * 4296 * @permission ohos.permission.INTERNET 4297 * @param { AsyncCallback<void> } callback callback function with a boolean argument indicating the calling result. 4298 * @throws { BusinessError } 201 - Permission denied. 4299 * @throws { BusinessError } 13400003 - task service ability error. 4300 * @throws { BusinessError } 21900007 - task state error. 4301 * @syscap SystemCapability.Request.FileTransferAgent 4302 * @since 10 4303 */ 4304 /** 4305 * Starts the task. 4306 * 4307 * @permission ohos.permission.INTERNET 4308 * @param { AsyncCallback<void> } callback callback function with a boolean argument indicating the calling result. 4309 * @throws { BusinessError } 201 - Permission denied. 4310 * @throws { BusinessError } 13400003 - task service ability error. 4311 * @throws { BusinessError } 21900007 - task state error. 4312 * @syscap SystemCapability.Request.FileTransferAgent 4313 * @crossplatform 4314 * @atomicservice 4315 * @since 11 4316 */ 4317 start(callback: AsyncCallback<void>): void; 4318 /** 4319 * Starts the task. 4320 * 4321 * @permission ohos.permission.INTERNET 4322 * @returns { Promise<void> } the promise returned by the function. 4323 * @throws { BusinessError } 201 - Permission denied. 4324 * @throws { BusinessError } 13400003 - task service ability error. 4325 * @throws { BusinessError } 21900007 - task state error. 4326 * @syscap SystemCapability.Request.FileTransferAgent 4327 * @since 10 4328 */ 4329 /** 4330 * Starts the task. 4331 * 4332 * @permission ohos.permission.INTERNET 4333 * @returns { Promise<void> } the promise returned by the function. 4334 * @throws { BusinessError } 201 - Permission denied. 4335 * @throws { BusinessError } 13400003 - task service ability error. 4336 * @throws { BusinessError } 21900007 - task state error. 4337 * @syscap SystemCapability.Request.FileTransferAgent 4338 * @crossplatform 4339 * @atomicservice 4340 * @since 11 4341 */ 4342 start(): Promise<void>; 4343 /** 4344 * Pauses the background task. 4345 * 4346 * @param { AsyncCallback<void> } callback callback function with a boolean argument indicating the calling result. 4347 * @throws { BusinessError } 13400003 - task service ability error. 4348 * @throws { BusinessError } 21900005 - task mode error. 4349 * @throws { BusinessError } 21900007 - task state error. 4350 * @syscap SystemCapability.Request.FileTransferAgent 4351 * @since 10 4352 */ 4353 /** 4354 * Pauses the task. 4355 * 4356 * @param { AsyncCallback<void> } callback - callback function with a boolean argument indicating the calling result. 4357 * @throws { BusinessError } 13400003 - task service ability error. 4358 * @throws { BusinessError } 21900007 - task state error. 4359 * @syscap SystemCapability.Request.FileTransferAgent 4360 * @since 11 4361 */ 4362 pause(callback: AsyncCallback<void>): void; 4363 /** 4364 * Pauses the background task. 4365 * 4366 * @returns { Promise<void> } the promise returned by the function. 4367 * @throws { BusinessError } 13400003 - task service ability error. 4368 * @throws { BusinessError } 21900005 - task mode error. 4369 * @throws { BusinessError } 21900007 - task state error. 4370 * @syscap SystemCapability.Request.FileTransferAgent 4371 * @since 10 4372 */ 4373 /** 4374 * Pauses the task. 4375 * 4376 * @returns { Promise<void> } the promise returned by the function. 4377 * @throws { BusinessError } 13400003 - task service ability error. 4378 * @throws { BusinessError } 21900007 - task state error. 4379 * @syscap SystemCapability.Request.FileTransferAgent 4380 * @since 11 4381 */ 4382 pause(): Promise<void>; 4383 /** 4384 * Resumes the background task. 4385 * 4386 * @permission ohos.permission.INTERNET 4387 * @param { AsyncCallback<void> } callback callback function with a boolean argument indicating the calling result. 4388 * @throws { BusinessError } 201 - Permission denied. 4389 * @throws { BusinessError } 13400003 - task service ability error. 4390 * @throws { BusinessError } 21900005 - task mode error. 4391 * @throws { BusinessError } 21900007 - task state error. 4392 * @syscap SystemCapability.Request.FileTransferAgent 4393 * @since 10 4394 */ 4395 /** 4396 * Resumes the task. 4397 * 4398 * @permission ohos.permission.INTERNET 4399 * @param { AsyncCallback<void> } callback - callback function with a boolean argument indicating the calling result. 4400 * @throws { BusinessError } 201 - Permission denied. 4401 * @throws { BusinessError } 13400003 - task service ability error. 4402 * @throws { BusinessError } 21900007 - task state error. 4403 * @syscap SystemCapability.Request.FileTransferAgent 4404 * @since 11 4405 */ 4406 resume(callback: AsyncCallback<void>): void; 4407 /** 4408 * Resumes the background task. 4409 * 4410 * @permission ohos.permission.INTERNET 4411 * @returns { Promise<void> } the promise returned by the function. 4412 * @throws { BusinessError } 201 - Permission denied. 4413 * @throws { BusinessError } 13400003 - task service ability error. 4414 * @throws { BusinessError } 21900005 - task mode error. 4415 * @throws { BusinessError } 21900007 - task state error. 4416 * @syscap SystemCapability.Request.FileTransferAgent 4417 * @since 10 4418 */ 4419 /** 4420 * Resumes the task. 4421 * 4422 * @permission ohos.permission.INTERNET 4423 * @returns { Promise<void> } the promise returned by the function. 4424 * @throws { BusinessError } 201 - Permission denied. 4425 * @throws { BusinessError } 13400003 - task service ability error. 4426 * @throws { BusinessError } 21900007 - task state error. 4427 * @syscap SystemCapability.Request.FileTransferAgent 4428 * @since 11 4429 */ 4430 resume(): Promise<void>; 4431 /** 4432 * Stops the task. 4433 * 4434 * @param { AsyncCallback<void> } callback callback function with a boolean argument indicating the calling result. 4435 * @throws { BusinessError } 13400003 - task service ability error. 4436 * @throws { BusinessError } 21900007 - task state error. 4437 * @syscap SystemCapability.Request.FileTransferAgent 4438 * @since 10 4439 */ 4440 /** 4441 * Stops the task. 4442 * 4443 * @param { AsyncCallback<void> } callback callback function with a boolean argument indicating the calling result. 4444 * @throws { BusinessError } 13400003 - task service ability error. 4445 * @throws { BusinessError } 21900007 - task state error. 4446 * @syscap SystemCapability.Request.FileTransferAgent 4447 * @crossplatform 4448 * @atomicservice 4449 * @since 11 4450 */ 4451 stop(callback: AsyncCallback<void>): void; 4452 /** 4453 * Stops the task. 4454 * 4455 * @returns { Promise<void> } the promise returned by the function. 4456 * @throws { BusinessError } 13400003 - task service ability error. 4457 * @throws { BusinessError } 21900007 - task state error. 4458 * @syscap SystemCapability.Request.FileTransferAgent 4459 * @since 10 4460 */ 4461 /** 4462 * Stops the task. 4463 * 4464 * @returns { Promise<void> } the promise returned by the function. 4465 * @throws { BusinessError } 13400003 - task service ability error. 4466 * @throws { BusinessError } 21900007 - task state error. 4467 * @syscap SystemCapability.Request.FileTransferAgent 4468 * @crossplatform 4469 * @atomicservice 4470 * @since 11 4471 */ 4472 stop(): Promise<void>; 4473 } 4474 4475 /** 4476 * Creates a task for upload or download and enqueue it. 4477 * Only foreground application can create the frontend task. 4478 * It can deal only one frontend task at a time. 4479 * A in processing frontend task will be forced to stop when its application had switched to background. 4480 * A new frontend task will interrupt a existed in processing frontend task. 4481 * The background task is highly recommended. 4482 * 4483 * @permission ohos.permission.INTERNET 4484 * @param { BaseContext } context context of the caller. 4485 * @param { Config } config configurations for a task. 4486 * @param { AsyncCallback<Task> } callback indicate the callback function to receive Task. 4487 * @throws { BusinessError } 201 - permission denied. 4488 * @throws { BusinessError } 401 - parameter error. 4489 * @throws { BusinessError } 13400001 - file operation error. 4490 * @throws { BusinessError } 13400003 - task service ability error. 4491 * @throws { BusinessError } 21900004 - application task queue full error. 4492 * @throws { BusinessError } 21900005 - task mode error. 4493 * @syscap SystemCapability.Request.FileTransferAgent 4494 * @since 10 4495 */ 4496 /** 4497 * Creates a task for upload or download and enqueue it. 4498 * When an application enters the background, the frontend tasks associated. 4499 * with it will gradually be paused until the application returns to the foreground. 4500 * 4501 * @permission ohos.permission.INTERNET 4502 * @param { BaseContext } context context of the caller. 4503 * @param { Config } config configurations for a task. 4504 * @param { AsyncCallback<Task> } callback indicate the callback function to receive Task. 4505 * @throws { BusinessError } 201 - permission denied. 4506 * @throws { BusinessError } 401 - parameter error. 4507 * @throws { BusinessError } 13400001 - file operation error. 4508 * @throws { BusinessError } 13400003 - task service ability error. 4509 * @throws { BusinessError } 21900004 - application task queue full error. 4510 * @throws { BusinessError } 21900005 - task mode error. 4511 * @syscap SystemCapability.Request.FileTransferAgent 4512 * @crossplatform 4513 * @atomicservice 4514 * @since 11 4515 */ 4516 function create(context: BaseContext, config: Config, callback: AsyncCallback<Task>): void; 4517 4518 /** 4519 * Creates a task for upload or download and enqueue it. 4520 * Only foreground application can create the frontend task. 4521 * It can deal only one frontend task at a time. 4522 * A in processing frontend task will be forced to stop when its application had switched to background. 4523 * A new frontend task will interrupt a existed in processing frontend task. 4524 * The background task is highly recommended. 4525 * 4526 * @permission ohos.permission.INTERNET 4527 * @param { BaseContext } context context of the caller. 4528 * @param { Config } config configurations for a task. 4529 * @returns { Promise<Task> } the promise returned by the function. 4530 * @throws { BusinessError } 201 - permission denied. 4531 * @throws { BusinessError } 401 - parameter error. 4532 * @throws { BusinessError } 13400001 - file operation error. 4533 * @throws { BusinessError } 13400003 - task service ability error. 4534 * @throws { BusinessError } 21900004 - application task queue full error. 4535 * @throws { BusinessError } 21900005 - task mode error. 4536 * @syscap SystemCapability.Request.FileTransferAgent 4537 * @since 10 4538 */ 4539 /** 4540 * Creates a task for upload or download and enqueue it. 4541 * When an application enters the background, the frontend tasks associated. 4542 * with it will gradually be paused until the application returns to the foreground. 4543 * 4544 * @permission ohos.permission.INTERNET 4545 * @param { BaseContext } context context of the caller. 4546 * @param { Config } config configurations for a task. 4547 * @returns { Promise<Task> } the promise returned by the function. 4548 * @throws { BusinessError } 201 - permission denied. 4549 * @throws { BusinessError } 401 - parameter error. 4550 * @throws { BusinessError } 13400001 - file operation error. 4551 * @throws { BusinessError } 13400003 - task service ability error. 4552 * @throws { BusinessError } 21900004 - application task queue full error. 4553 * @throws { BusinessError } 21900005 - task mode error. 4554 * @syscap SystemCapability.Request.FileTransferAgent 4555 * @crossplatform 4556 * @atomicservice 4557 * @since 11 4558 */ 4559 function create(context: BaseContext, config: Config): Promise<Task>; 4560 4561 /** 4562 * Gets the task with the specified id. 4563 * 4564 * @param { BaseContext } context - context of the caller. 4565 * @param { string } id - the id of the task. 4566 * @param { string } token - the token of the task. 4567 * @returns { Promise<Task> } the promise returned by the function. 4568 * @throws { BusinessError } 401 - parameter error. 4569 * @throws { BusinessError } 13400003 - task service ability error. 4570 * @throws { BusinessError } 21900006 - task not found error. 4571 * @syscap SystemCapability.Request.FileTransferAgent 4572 * @since 11 4573 */ 4574 function getTask(context: BaseContext, id: string, token?: string): Promise<Task>; 4575 4576 /** 4577 * Removes specified task belongs to the caller. 4578 * The task will be forced to stop if in processing. 4579 * 4580 * @param { string } id the task id. 4581 * @param { AsyncCallback<void> } callback callback function with a boolean argument indicating success or not. 4582 * @throws { BusinessError } 401 - parameter error. 4583 * @throws { BusinessError } 13400003 - task service ability error. 4584 * @throws { BusinessError } 21900006 - task not found error. 4585 * @syscap SystemCapability.Request.FileTransferAgent 4586 * @since 10 4587 */ 4588 /** 4589 * Removes specified task belongs to the caller. 4590 * The task will be forced to stop if in processing. 4591 * 4592 * @param { string } id the task id. 4593 * @param { AsyncCallback<void> } callback callback function with a boolean argument indicating success or not. 4594 * @throws { BusinessError } 401 - parameter error. 4595 * @throws { BusinessError } 13400003 - task service ability error. 4596 * @throws { BusinessError } 21900006 - task not found error. 4597 * @syscap SystemCapability.Request.FileTransferAgent 4598 * @crossplatform 4599 * @atomicservice 4600 * @since 11 4601 */ 4602 function remove(id: string, callback: AsyncCallback<void>): void; 4603 4604 /** 4605 * Removes specified task belongs to the caller. 4606 * The task will be forced to stop if in processing. 4607 * 4608 * @param { string } id the task id. 4609 * @returns { Promise<void> } the promise returned by the function. 4610 * @throws { BusinessError } 401 - parameter error. 4611 * @throws { BusinessError } 13400003 - task service ability error. 4612 * @throws { BusinessError } 21900006 - task not found error. 4613 * @syscap SystemCapability.Request.FileTransferAgent 4614 * @since 10 4615 */ 4616 /** 4617 * Removes specified task belongs to the caller. 4618 * The task will be forced to stop if in processing. 4619 * 4620 * @param { string } id the task id. 4621 * @returns { Promise<void> } the promise returned by the function. 4622 * @throws { BusinessError } 401 - parameter error. 4623 * @throws { BusinessError } 13400003 - task service ability error. 4624 * @throws { BusinessError } 21900006 - task not found error. 4625 * @syscap SystemCapability.Request.FileTransferAgent 4626 * @crossplatform 4627 * @atomicservice 4628 * @since 11 4629 */ 4630 function remove(id: string): Promise<void>; 4631 4632 /** 4633 * Shows specified task details belongs to the caller. 4634 * 4635 * @param { string } id the task id. 4636 * @param { AsyncCallback<TaskInfo> } callback callback function with a `TaskInfo` argument for informations of the current task. 4637 * @throws { BusinessError } 401 - parameter error. 4638 * @throws { BusinessError } 13400003 - task service ability error. 4639 * @throws { BusinessError } 21900006 - task not found error. 4640 * @syscap SystemCapability.Request.FileTransferAgent 4641 * @since 10 4642 */ 4643 /** 4644 * Shows specified task details belongs to the caller. 4645 * 4646 * @param { string } id the task id. 4647 * @param { AsyncCallback<TaskInfo> } callback callback function with a `TaskInfo` argument for informations of the current task. 4648 * @throws { BusinessError } 401 - parameter error. 4649 * @throws { BusinessError } 13400003 - task service ability error. 4650 * @throws { BusinessError } 21900006 - task not found error. 4651 * @syscap SystemCapability.Request.FileTransferAgent 4652 * @crossplatform 4653 * @since 11 4654 */ 4655 function show(id: string, callback: AsyncCallback<TaskInfo>): void; 4656 4657 /** 4658 * Shows specified task details belongs to the caller. 4659 * 4660 * @param { string } id the task id. 4661 * @returns { Promise<TaskInfo> } the promise returned by the function. 4662 * @throws { BusinessError } 401 - parameter error. 4663 * @throws { BusinessError } 13400003 - task service ability error. 4664 * @throws { BusinessError } 21900006 - task not found error. 4665 * @syscap SystemCapability.Request.FileTransferAgent 4666 * @since 10 4667 */ 4668 /** 4669 * Shows specified task details belongs to the caller. 4670 * 4671 * @param { string } id the task id. 4672 * @returns { Promise<TaskInfo> } the promise returned by the function. 4673 * @throws { BusinessError } 401 - parameter error. 4674 * @throws { BusinessError } 13400003 - task service ability error. 4675 * @throws { BusinessError } 21900006 - task not found error. 4676 * @syscap SystemCapability.Request.FileTransferAgent 4677 * @crossplatform 4678 * @since 11 4679 */ 4680 function show(id: string): Promise<TaskInfo>; 4681 4682 /** 4683 * Touches specified task with token. 4684 * 4685 * @param { string } id the task id. 4686 * @param { string } token the in-application isolation key. 4687 * @param { AsyncCallback<TaskInfo> } callback callback function with a `TaskInfo` argument for informations of the current task. 4688 * @throws { BusinessError } 401 - parameter error. 4689 * @throws { BusinessError } 13400003 - task service ability error. 4690 * @throws { BusinessError } 21900006 - task not found error. 4691 * @syscap SystemCapability.Request.FileTransferAgent 4692 * @since 10 4693 */ 4694 /** 4695 * Touches specified task with token. 4696 * 4697 * @param { string } id the task id. 4698 * @param { string } token the in-application isolation key. 4699 * @param { AsyncCallback<TaskInfo> } callback callback function with a `TaskInfo` argument for informations of the current task. 4700 * @throws { BusinessError } 401 - parameter error. 4701 * @throws { BusinessError } 13400003 - task service ability error. 4702 * @throws { BusinessError } 21900006 - task not found error. 4703 * @syscap SystemCapability.Request.FileTransferAgent 4704 * @crossplatform 4705 * @since 11 4706 */ 4707 function touch(id: string, token: string, callback: AsyncCallback<TaskInfo>): void; 4708 4709 /** 4710 * Touches specified task with token. 4711 * 4712 * @param { string } id the task id. 4713 * @param { string } token the in-application isolation key. 4714 * @returns { Promise<TaskInfo> } the promise returned by the function. 4715 * @throws { BusinessError } 401 - parameter error. 4716 * @throws { BusinessError } 13400003 - task service ability error. 4717 * @throws { BusinessError } 21900006 - task not found error. 4718 * @syscap SystemCapability.Request.FileTransferAgent 4719 * @since 10 4720 */ 4721 /** 4722 * Touches specified task with token. 4723 * 4724 * @param { string } id the task id. 4725 * @param { string } token the in-application isolation key. 4726 * @returns { Promise<TaskInfo> } the promise returned by the function. 4727 * @throws { BusinessError } 401 - parameter error. 4728 * @throws { BusinessError } 13400003 - task service ability error. 4729 * @throws { BusinessError } 21900006 - task not found error. 4730 * @syscap SystemCapability.Request.FileTransferAgent 4731 * @crossplatform 4732 * @since 11 4733 */ 4734 function touch(id: string, token: string): Promise<TaskInfo>; 4735 4736 /** 4737 * Searches tasks, for system. 4738 * 4739 * @param { AsyncCallback<Array<string>> } callback callback function with a `Array<string>` argument contains task ids match filter. 4740 * @throws { BusinessError } 401 - parameter error. 4741 * @throws { BusinessError } 13400003 - task service ability error. 4742 * @syscap SystemCapability.Request.FileTransferAgent 4743 * @since 10 4744 */ 4745 /** 4746 * Searches tasks, for system. 4747 * 4748 * @param { AsyncCallback<Array<string>> } callback callback function with a `Array<string>` argument contains task ids match filter. 4749 * @throws { BusinessError } 401 - parameter error. 4750 * @throws { BusinessError } 13400003 - task service ability error. 4751 * @syscap SystemCapability.Request.FileTransferAgent 4752 * @crossplatform 4753 * @since 11 4754 */ 4755 function search(callback: AsyncCallback<Array<string>>): void; 4756 4757 /** 4758 * Searches tasks, for system. 4759 * 4760 * @param { Filter } filter an instance of `Filter`. 4761 * @param { AsyncCallback<Array<string>> } callback callback function with a `Array<string>` argument contains task ids match filter. 4762 * @throws { BusinessError } 401 - parameter error. 4763 * @throws { BusinessError } 13400003 - task service ability error. 4764 * @syscap SystemCapability.Request.FileTransferAgent 4765 * @since 10 4766 */ 4767 /** 4768 * Searches tasks, for system. 4769 * 4770 * @param { Filter } filter an instance of `Filter`. 4771 * @param { AsyncCallback<Array<string>> } callback callback function with a `Array<string>` argument contains task ids match filter. 4772 * @throws { BusinessError } 401 - parameter error. 4773 * @throws { BusinessError } 13400003 - task service ability error. 4774 * @syscap SystemCapability.Request.FileTransferAgent 4775 * @crossplatform 4776 * @since 11 4777 */ 4778 function search(filter: Filter, callback: AsyncCallback<Array<string>>): void; 4779 4780 /** 4781 * Searches tasks, for system. 4782 * 4783 * @param { Filter } filter an instance of `Filter`. 4784 * @returns { Promise<Array<string>> } the promise returned by the function. 4785 * @throws { BusinessError } 401 - parameter error. 4786 * @throws { BusinessError } 13400003 - task service ability error. 4787 * @syscap SystemCapability.Request.FileTransferAgent 4788 * @since 10 4789 */ 4790 /** 4791 * Searches tasks, for system. 4792 * 4793 * @param { Filter } filter an instance of `Filter`. 4794 * @returns { Promise<Array<string>> } the promise returned by the function. 4795 * @throws { BusinessError } 401 - parameter error. 4796 * @throws { BusinessError } 13400003 - task service ability error. 4797 * @syscap SystemCapability.Request.FileTransferAgent 4798 * @crossplatform 4799 * @since 11 4800 */ 4801 function search(filter?: Filter): Promise<Array<string>>; 4802 4803 /** 4804 * Queries specified task details. 4805 * 4806 * @permission ohos.permission.DOWNLOAD_SESSION_MANAGER or ohos.permission.UPLOAD_SESSION_MANAGER 4807 * @param { string } id the task id. 4808 * @param { AsyncCallback<TaskInfo> } callback callback function with a `TaskInfo` argument for informations of the current task. 4809 * @throws { BusinessError } 201 - permission denied. 4810 * @throws { BusinessError } 202 - permission verification failed, application which is not a system application uses system API. 4811 * @throws { BusinessError } 401 - parameter error. 4812 * @throws { BusinessError } 13400003 - task service ability error. 4813 * @throws { BusinessError } 21900006 - task not found error. 4814 * @syscap SystemCapability.Request.FileTransferAgent 4815 * @systemapi Hide this for inner system use. 4816 * @since 10 4817 */ 4818 function query(id: string, callback: AsyncCallback<TaskInfo>): void; 4819 4820 /** 4821 * Queries specified task details. 4822 * 4823 * @permission ohos.permission.DOWNLOAD_SESSION_MANAGER or ohos.permission.UPLOAD_SESSION_MANAGER 4824 * @param { string } id the task id. 4825 * @returns { Promise<TaskInfo> } the promise returned by the function. 4826 * @throws { BusinessError } 201 - permission denied. 4827 * @throws { BusinessError } 202 - permission verification failed, application which is not a system application uses system API. 4828 * @throws { BusinessError } 401 - parameter error. 4829 * @throws { BusinessError } 13400003 - task service ability error. 4830 * @throws { BusinessError } 21900006 - task not found error. 4831 * @syscap SystemCapability.Request.FileTransferAgent 4832 * @systemapi Hide this for inner system use. 4833 * @since 10 4834 */ 4835 function query(id: string): Promise<TaskInfo>; 4836 } 4837} 4838 4839export default request; 4840