1# @ohos.file.cloudSync (Device-Cloud Sync) (System API) 2 3The **cloudSync** module provides the device-cloud sync capabilities for applications. You can use the APIs to start or stop device-cloud sync and start or stop the download of images. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.file.cloudSync (Device-Cloud Sync Capability)](js-apis-file-cloudsync.md). 9 10## Modules to Import 11 12```ts 13import { cloudSync } from '@kit.CoreFileKit'; 14``` 15 16## GallerySync 17 18Provides APIs to implement device-cloud sync of media assets in **Gallery**. Before using the APIs of **GallerySync**, you need to create a **GallerySync** instance. 19 20### constructor 21 22constructor() 23 24A constructor used to create a **GallerySync** instance. 25 26**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 27 28**System API**: This is a system API. 29 30**Example** 31 32 ```ts 33 let gallerySync = new cloudSync.GallerySync() 34 ``` 35 36### on 37 38on(evt: 'progress', callback: (pg: SyncProgress) => void): void 39 40Registers a listener for the device-cloud sync progress. 41 42**Required permissions**: ohos.permission.CLOUDFILE_SYNC 43 44**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 45 46**System API**: This is a system API. 47 48**Parameters** 49 50| Name | Type | Mandatory| Description| 51| ---------- | ------ | ---- | ---- | 52| evt | string | Yes | Event type. The value is **progress**, which indicates the sync progress event.| 53| callback | (pg: SyncProgress) => void | Yes | Callback of the sync progress event. The input parameter is [SyncProgress](./js-apis-file-cloudsync.md#syncprogress12), and the return value is void.| 54 55**Error codes** 56 57For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 58 59| ID | Error Message | 60| ---------------------------- | ---------- | 61| 201 | Permission verification failed. | 62| 202 | The caller is not a system application. | 63| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 64| 13600001 | IPC error. | 65 66**Example** 67 68 ```ts 69 let gallerySync = new cloudSync.GallerySync(); 70 71 gallerySync.on('progress', (pg: cloudSync.SyncProgress) => { 72 console.info("syncState: " + pg.state); 73 }); 74 ``` 75 76### off 77 78off(evt: 'progress', callback: (pg: SyncProgress) => void): void 79 80Unregisters a listener for the device-cloud sync progress. 81 82**Required permissions**: ohos.permission.CLOUDFILE_SYNC 83 84**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 85 86**System API**: This is a system API. 87 88**Parameters** 89 90| Name | Type | Mandatory| Description| 91| ---------- | ------ | ---- | ---- | 92| evt | string | Yes | Event type. The value is **progress**, which indicates the sync progress event.| 93| callback | (pg: SyncProgress) => void | Yes | Callback of the sync progress event. The input parameter is [SyncProgress](./js-apis-file-cloudsync.md#syncprogress12), and the return value is void.| 94 95**Error codes** 96 97For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 98 99| ID | Error Message | 100| ---------------------------- | ---------- | 101| 201 | Permission verification failed. | 102| 202 | The caller is not a system application. | 103| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 104| 13600001 | IPC error. | 105 106**Example** 107 108 ```ts 109 let gallerySync = new cloudSync.GallerySync(); 110 111 let callback = (pg: cloudSync.SyncProgress) => { 112 console.info("gallery sync state: " + pg.state + "error type:" + pg.error); 113 } 114 115 gallerySync.on('progress', callback); 116 117 gallerySync.off('progress', callback); 118 ``` 119 120### off 121 122off(evt: 'progress'): void 123 124Unregisters all listeners for the device-cloud sync progress. 125 126**Required permissions**: ohos.permission.CLOUDFILE_SYNC 127 128**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 129 130**System API**: This is a system API. 131 132**Parameters** 133 134| Name | Type | Mandatory| Description| 135| ---------- | ------ | ---- | ---- | 136| evt | string | Yes | Event type. The value is **progress**, which indicates the sync progress event.| 137 138**Error codes** 139 140For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 141 142| ID | Error Message | 143| ---------------------------- | ---------- | 144| 201 | Permission verification failed. | 145| 202 | The caller is not a system application. | 146| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 147| 13600001 | IPC error. | 148 149**Example** 150 151 ```ts 152 let gallerySync = new cloudSync.GallerySync(); 153 154 gallerySync.on('progress', (pg: cloudSync.SyncProgress) => { 155 console.info("syncState: " + pg.state); 156 }); 157 158 gallerySync.off('progress'); 159 ``` 160 161### start 162 163start(): Promise<void> 164 165Starts device-cloud sync. This API uses a promise to return the result. 166 167**Required permissions**: ohos.permission.CLOUDFILE_SYNC 168 169**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 170 171**System API**: This is a system API. 172 173**Return value** 174 175| Type | Description | 176| --------------------- | ---------------- | 177| Promise<void> | Promise used to return the result.| 178 179**Error codes** 180 181For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 182 183| ID | Error Message | 184| ---------------------------- | ---------- | 185| 201 | Permission verification failed. | 186| 202 | The caller is not a system application. | 187| 401 | The input parameter is invalid. Possible causes:Incorrect parameter types. | 188| 22400001 | Cloud status not ready. | 189| 22400002 | Network unavailable. | 190| 22400003 | Low battery level. | 191 192**Example** 193 194 ```ts 195 import { BusinessError } from '@kit.BasicServicesKit'; 196 let gallerySync = new cloudSync.GallerySync(); 197 198 gallerySync.on('progress', (pg: cloudSync.SyncProgress) => { 199 console.info("syncState: " + pg.state); 200 }); 201 202 gallerySync.start().then(() => { 203 console.info("start sync successfully"); 204 }).catch((err: BusinessError) => { 205 console.error("start sync failed with error message: " + err.message + ", error code: " + err.code); 206 }); 207 ``` 208 209### start 210 211start(callback: AsyncCallback<void>): void 212 213Starts device-cloud sync. This API uses an asynchronous callback to return the result. 214 215**Required permissions**: ohos.permission.CLOUDFILE_SYNC 216 217**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 218 219**System API**: This is a system API. 220 221**Parameters** 222 223| Name | Type | Mandatory| Description| 224| ---------- | ------ | ---- | ---- | 225| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 226 227**Error codes** 228 229For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 230 231| ID | Error Message | 232| ---------------------------- | ---------- | 233| 201 | Permission verification failed. | 234| 202 | The caller is not a system application. | 235| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 236| 22400001 | Cloud status not ready. | 237| 22400002 | Network unavailable. | 238| 22400003 | Low battery level. | 239 240**Example** 241 242 ```ts 243 import { BusinessError } from '@kit.BasicServicesKit'; 244 let gallerySync = new cloudSync.GallerySync(); 245 246 gallerySync.start((err: BusinessError) => { 247 if (err) { 248 console.error("start sync failed with error message: " + err.message + ", error code: " + err.code); 249 } else { 250 console.info("start sync successfully"); 251 } 252 }); 253 ``` 254 255### stop 256 257stop(): Promise<void> 258 259Stops device-cloud sync. This API uses a promise to return the result. 260 261> **NOTE** 262> 263> Calling **stop** will stop the sync process. To resume the sync, call [start](#start). 264 265**Required permissions**: ohos.permission.CLOUDFILE_SYNC 266 267**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 268 269**System API**: This is a system API. 270 271**Return value** 272 273| Type | Description | 274| --------------------- | ---------------- | 275| Promise<void> | Promise used to return the result.| 276 277**Error codes** 278 279For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 280 281| ID | Error Message | 282| ---------------------------- | ---------- | 283| 201 | Permission verification failed. | 284| 202 | The caller is not a system application. | 285| 401 | The input parameter is invalid. Possible causes:Incorrect parameter types. | 286 287**Example** 288 289 ```ts 290 import { BusinessError } from '@kit.BasicServicesKit'; 291 let gallerySync = new cloudSync.GallerySync(); 292 293 gallerySync.stop().then(() => { 294 console.info("stop sync successfully"); 295 }).catch((err: BusinessError) => { 296 console.error("stop sync failed with error message: " + err.message + ", error code: " + err.code); 297 }); 298 ``` 299 300### stop 301 302stop(callback: AsyncCallback<void>): void 303 304Stops device-cloud sync. This API uses an asynchronous callback to return the result. 305 306> **NOTE** 307> 308> Calling **stop** will stop the sync process. To resume the sync, call [start](#start). 309 310**Required permissions**: ohos.permission.CLOUDFILE_SYNC 311 312**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 313 314**System API**: This is a system API. 315 316**Parameters** 317 318| Name | Type | Mandatory| Description| 319| ---------- | ------ | ---- | ---- | 320| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 321 322**Error codes** 323 324For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 325 326| ID | Error Message | 327| ---------------------------- | ---------- | 328| 201 | Permission verification failed. | 329| 202 | The caller is not a system application. | 330| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 331 332**Example** 333 334 ```ts 335 import { BusinessError } from '@kit.BasicServicesKit'; 336 let gallerySync = new cloudSync.GallerySync(); 337 338 gallerySync.stop((err: BusinessError) => { 339 if (err) { 340 console.error("stop sync failed with error message: " + err.message + ", error code: " + err.code); 341 } else { 342 console.info("stop sync successfully"); 343 } 344 }); 345 ``` 346 347## Download 348 349Provides APIs for downloading image files to **Gallery**. Before using the APIs of **Download**, you need to create a **Download** instance. 350 351### constructor 352 353constructor() 354 355A constructor used to create a **Download** instance. 356 357**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 358 359**System API**: This is a system API. 360 361**Example** 362 363 ```ts 364 let download = new cloudSync.Download() 365 ``` 366 367### on 368 369on(evt: 'progress', callback: (pg: DownloadProgress) => void): void 370 371Registers a listener for the download progress of a cloud file. 372 373**Required permissions**: ohos.permission.CLOUDFILE_SYNC 374 375**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 376 377**System API**: This is a system API. 378 379**Parameters** 380 381| Name | Type | Mandatory| Description| 382| ---------- | ------ | ---- | ---- | 383| evt | string | Yes | Event. The value is **progress**, which indicates the download progress event of a cloud file.| 384| callback | (pg: DownloadProgress) => void | Yes | Callback used to return the file download progress. The input parameter is [DownloadProgress](js-apis-file-cloudsync.md#downloadprogress11), and the return value is **void**.| 385 386**Error codes** 387 388For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 389 390| ID | Error Message | 391| ---------------------------- | ---------- | 392| 201 | Permission verification failed. | 393| 202 | The caller is not a system application. | 394| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 395| 13600001 | IPC error. | 396 397**Example** 398 399 ```ts 400 let download = new cloudSync.Download(); 401 402 download.on('progress', (pg: cloudSync.DownloadProgress) => { 403 console.info("download state: " + pg.state); 404 }); 405 ``` 406 407### off 408 409off(evt: 'progress', callback: (pg: DownloadProgress) => void): void 410 411Unregisters a listener for the download progress of a cloud file. 412 413**Required permissions**: ohos.permission.CLOUDFILE_SYNC 414 415**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 416 417**System API**: This is a system API. 418 419**Parameters** 420 421| Name | Type | Mandatory| Description| 422| ---------- | ------ | ---- | ---- | 423| evt | string | Yes | Event type. The value is **progress**, which indicates the sync progress event.| 424| callback | (pg: DownloadProgress) => void | Yes | Callback used to return the file download progress. The input parameter is [DownloadProgress](js-apis-file-cloudsync.md#downloadprogress11), and the return value is **void**.| 425 426**Error codes** 427 428For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 429 430| ID | Error Message | 431| ---------------------------- | ---------- | 432| 201 | Permission verification failed. | 433| 202 | The caller is not a system application. | 434| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 435| 13600001 | IPC error. | 436 437**Example** 438 439 ```ts 440 let download = new cloudSync.Download(); 441 442 let callback = (pg: cloudSync.DownloadProgress) => { 443 console.info("download state: " + pg.state); 444 } 445 446 download.on('progress', callback); 447 448 download.off('progress', callback); 449 ``` 450 451### off 452 453off(evt: 'progress'): void 454 455Unregisters all listeners for the download progress event of a cloud file. 456 457**Required permissions**: ohos.permission.CLOUDFILE_SYNC 458 459**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 460 461**System API**: This is a system API. 462 463**Parameters** 464 465| Name | Type | Mandatory| Description| 466| ---------- | ------ | ---- | ---- | 467| evt | string | Yes | Event type. The value is **progress**, which indicates the download progress event of a cloud file.| 468 469**Error codes** 470 471For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 472 473| ID | Error Message | 474| ---------------------------- | ---------- | 475| 201 | Permission verification failed. | 476| 202 | The caller is not a system application. | 477| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 478| 13600001 | IPC error. | 479 480**Example** 481 482 ```ts 483 let download = new cloudSync.Download(); 484 485 download.on('progress', (pg: cloudSync.DownloadProgress) => { 486 console.info("download state:" + pg.state); 487 }); 488 489 download.off('progress'); 490 ``` 491 492### start 493 494start(uri: string): Promise<void> 495 496Starts to download a cloud file. This API uses a promise to return the result. 497 498**Required permissions**: ohos.permission.CLOUDFILE_SYNC 499 500**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 501 502**System API**: This is a system API. 503 504**Parameters** 505 506| Name | Type | Mandatory| Description| 507| ---------- | ------ | ---- | ---- | 508| uri | string | Yes | URI of the target file.| 509 510**Return value** 511 512| Type | Description | 513| --------------------- | ---------------- | 514| Promise<void> | Promise used to return the result.| 515 516**Example** 517 518 ```ts 519 import { BusinessError } from '@kit.BasicServicesKit'; 520 let download = new cloudSync.Download(); 521 let uri: string = "file:///media/Photo/1"; 522 523 download.on('progress', (pg: cloudSync.DownloadProgress) => { 524 console.info("download state:" + pg.state); 525 }); 526 527 download.start(uri).then(() => { 528 console.info("start download successfully"); 529 }).catch((err: BusinessError) => { 530 console.error("start download failed with error message: " + err.message + ", error code: " + err.code); 531 }); 532 ``` 533 534**Error codes** 535 536For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 537 538| ID | Error Message | 539| ---------------------------- | ---------- | 540| 201 | Permission verification failed. | 541| 202 | The caller is not a system application. | 542| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 543| 13900002 | No such file or directory. | 544| 13900025 | No space left on device. | 545 546### start 547 548start(uri: string, callback: AsyncCallback<void>): void 549 550Starts to download a cloud file. This API uses an asynchronous callback to return the result. 551 552**Required permissions**: ohos.permission.CLOUDFILE_SYNC 553 554**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 555 556**System API**: This is a system API. 557 558**Parameters** 559 560| Name | Type | Mandatory| Description| 561| ---------- | ------ | ---- | ---- | 562| uri | string | Yes | URI of the target file.| 563| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 564 565**Error codes** 566 567For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 568 569| ID | Error Message | 570| ---------------------------- | ---------- | 571| 201 | Permission verification failed. | 572| 202 | The caller is not a system application. | 573| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 574| 13900002 | No such file or directory. | 575| 13900025 | No space left on device. | 576 577**Example** 578 579 ```ts 580 import { BusinessError } from '@kit.BasicServicesKit'; 581 let download = new cloudSync.Download(); 582 let uri: string = "file:///media/Photo/1"; 583 584 download.start(uri, (err: BusinessError) => { 585 if (err) { 586 console.error("start download failed with error message: " + err.message + ", error code: " + err.code); 587 } else { 588 console.info("start download successfully"); 589 } 590 }); 591 ``` 592 593### stop 594 595stop(uri: string): Promise<void> 596 597Stops downloading a cloud file. This API uses a promise to return the result. 598 599> **NOTE** 600> 601> Calling **stop** will terminate the download of the current file and clear the cache file. You can use **start** to start the download again. 602 603**Required permissions**: ohos.permission.CLOUDFILE_SYNC 604 605**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 606 607**System API**: This is a system API. 608 609**Parameters** 610 611| Name | Type | Mandatory| Description| 612| ---------- | ------ | ---- | ---- | 613| uri | string | Yes | URI of the target file.| 614 615**Return value** 616 617| Type | Description | 618| --------------------- | ---------------- | 619| Promise<void> | Promise used to return the result.| 620 621**Error codes** 622 623For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 624 625| ID | Error Message | 626| ---------------------------- | ---------- | 627| 201 | Permission verification failed. | 628| 202 | The caller is not a system application. | 629| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 630 631**Example** 632 633 ```ts 634 import { BusinessError } from '@kit.BasicServicesKit'; 635 let download = new cloudSync.Download(); 636 let uri: string = "file:///media/Photo/1"; 637 638 download.stop(uri).then(() => { 639 console.info("stop download successfully"); 640 }).catch((err: BusinessError) => { 641 console.error("stop download failed with error message: " + err.message + ", error code: " + err.code); 642 }); 643 ``` 644 645### stop 646 647stop(uri: string, callback: AsyncCallback<void>): void 648 649Stops downloading a cloud file. This API uses an asynchronous callback to return the result. 650 651> **NOTE** 652> 653> Calling **stop** will terminate the download of the current file and clear the cache file. You can use **start** to start the download again. 654 655**Required permissions**: ohos.permission.CLOUDFILE_SYNC 656 657**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 658 659**System API**: This is a system API. 660 661**Parameters** 662 663| Name | Type | Mandatory| Description| 664| ---------- | ------ | ---- | ---- | 665| uri | string | Yes | URI of the target file.| 666| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 667 668**Error codes** 669 670For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 671 672| ID | Error Message | 673| ---------------------------- | ---------- | 674| 201 | Permission verification failed. | 675| 202 | The caller is not a system application. | 676| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 677 678**Example** 679 680 ```ts 681 import { BusinessError } from '@kit.BasicServicesKit'; 682 let download = new cloudSync.Download(); 683 let uri: string = "file:///media/Photo/1"; 684 685 download.stop(uri, (err: BusinessError) => { 686 if (err) { 687 console.error("stop download failed with error message: " + err.message + ", error code: " + err.code); 688 } else { 689 console.info("stop download successfully"); 690 } 691 }); 692 ``` 693 694## FileSync<sup>12+</sup> 695 696Provides APIs for the file manager application to perform device-cloud sync of the files stored in the Drive Kit. Before using the APIs of this class, you need to create a **FileSync** instance. 697 698### constructor<sup>12+</sup> 699 700constructor(bundleName: string) 701 702A constructor used to create a **FileSync** instance. 703 704**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 705 706**System API**: This is a system API. 707 708**Parameters** 709 710| Name | Type | Mandatory| Description| 711| ---------- | ------ | ---- | ---- | 712| bundleName | string | Yes | Bundle name.| 713 714**Error codes** 715 716For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 717 718| ID | Error Message | 719| ---------------------------- | ---------- | 720| 202 | Permission verification failed, application which is not a system application uses system API. | 721| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 722 723**Example** 724 725 ```ts 726 let fileSync = new cloudSync.FileSync("com.ohos.demo") 727 ``` 728 729## CloudFileCache<sup>11+</sup> 730 731Provides APIs for the file manager application to download files from the Drive Kit to a local device. 732 733**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 734 735### cleanCache<sup>11+</sup> 736 737cleanCache(uri: string): void 738 739Deletes a cache file. This API returns the result synchronously. 740 741**Required permissions**: ohos.permission.CLOUDFILE_SYNC 742 743**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 744 745**System API**: This is a system API. 746 747**Parameters** 748 749| Name | Type | Mandatory| Description| 750| ---------- | ------ | ---- | ---- | 751| uri | string | Yes | URI of the cache file to delete.| 752 753**Error codes** 754 755For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 756 757| ID | Error Message | 758| ---------------------------- | ---------- | 759| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 760| 202 | Permission verification failed, application which is not a system application uses system API. | 761| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 762| 13600001 | IPC error. | 763| 13900002 | No such file or directory. | 764| 14000002 | Invalid URI. | 765 766**Example** 767 768 ```ts 769 import { BusinessError } from '@kit.BasicServicesKit'; 770 import { fileUri } from '@kit.CoreFileKit'; 771 let fileCache = new cloudSync.CloudFileCache(); 772 let path = "/data/storage/el2/cloud/1.txt"; 773 let uri = fileUri.getUriFromPath(path); 774 775 try { 776 fileCache.cleanCache(uri); 777 } catch (err) { 778 let error:BusinessError = err as BusinessError; 779 console.error("clean cache failed with error message: " + err.message + ", error code: " + err.code); 780 } 781 782 ``` 783 784## cloudSync.getFileSyncState<sup>11+</sup> 785 786getFileSyncState(uri: Array<string>): Promise<Array<FileSyncState>> 787 788Obtains the file sync state. This API uses a promise to return the result. 789 790**Required permissions**: ohos.permission.CLOUDFILE_SYNC 791 792**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 793 794**System API**: This is a system API. 795 796**Parameters** 797 798| Name | Type | Mandatory| Description| 799| ---------- | ------ | ---- | ---- | 800| uri | Array<string> | Yes | URI of the file whose sync state is to be obtained.| 801 802**Return value** 803 804| Type | Description | 805| --------------------- | ---------------- | 806| Promise<Array<FileSyncState>> | Promise used to return the sync state obtained.| 807 808**Error codes** 809 810For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 811 812| ID | Error Message | 813| ---------------------------- | ---------- | 814| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 815| 202 | Permission verification failed, application which is not a system application uses system API. | 816| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 817| 13600001 | IPC error. | 818| 13900002 | No such file or directory. | 819| 14000002 | Invalid URI. | 820 821**Example** 822 823 ```ts 824 import { BusinessError } from '@kit.BasicServicesKit'; 825 826 let uris: Array<string> = ["file://uri"]; 827 cloudSync.getFileSyncState(uris).then((syncStates: Array<cloudSync.FileSyncState>) => { 828 for(let i = 0, len = syncStates.length; i < len; i++){ 829 console.info("get file sync state successfully" + syncStates[i]); 830 } 831 }).catch((err: BusinessError) => { 832 console.error("get file sync state failed with error message: " + err.message + ", error code: " + err.code); 833 }); 834 835 ``` 836 837## cloudSync.getFileSyncState<sup>11+</sup> 838 839getFileSyncState(uri: Array<string>, callback: AsyncCallback<Array<FileSyncState>>): void 840 841Obtains the file sync state. This API uses an asynchronous callback to return the result. 842 843**Required permissions**: ohos.permission.CLOUDFILE_SYNC 844 845**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 846 847**System API**: This is a system API. 848 849**Parameters** 850 851| Name | Type | Mandatory| Description| 852| ---------- | ------ | ---- | ---- | 853| uri | Array<string> | Yes | URI of the file whose sync state is to be obtained.| 854| callback | AsyncCallback<Array<FileSyncState>> | Yes | Callback used to return the file sync state.| 855 856**Error codes** 857 858For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 859 860| ID | Error Message | 861| ---------------------------- | ---------- | 862| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 863| 202 | Permission verification failed, application which is not a system application uses system API. | 864| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 865| 13600001 | IPC error. | 866| 13900002 | No such file or directory. | 867| 14000002 | Invalid URI. | 868 869**Example** 870 871 ```ts 872 import { BusinessError } from '@kit.BasicServicesKit'; 873 874 let uris: Array<string> = ["file://uri"]; 875 cloudSync.getFileSyncState(uris, (err: BusinessError, syncStates: Array<cloudSync.FileSyncState>) => { 876 if (err) { 877 console.error("get file sync state with error message: " + err.message + ", error code: " + err.code); 878 } else { 879 for(let i = 0, len = syncStates.length; i < len; i++){ 880 console.info("get file sync state successfully" + syncStates[i]); 881 } 882 } 883 }); 884 ``` 885 886## cloudSync.getFileSyncState<sup>12+</sup> 887 888getFileSyncState(uri: string): FileSyncState 889 890Obtains the file sync status. 891 892**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 893 894**System API**: This is a system API. 895 896**Parameters** 897 898| Name | Type | Mandatory| Description| 899| ---------- | ------ | ---- | ---- | 900| uri | string | Yes | URI of the target file.| 901 902**Return value** 903 904| Type | Description | 905| --------------------- | ---------------- | 906| [FileSyncState](#filesyncstate11) | Sync status of the file.| 907 908**Error codes** 909 910For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 911 912| ID | Error Message | 913| ---------------------------- | ---------- | 914| 202 | Permission verification failed, application which is not a system application uses system API. | 915| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 916| 13900002 | No such file or directory. | 917| 13900004 | Interrupted system call. | 918| 13900010 | Try again. | 919| 13900012 | Permission denied by the file system. | 920| 13900031 | Function not implemented. | 921| 13900042 | Unknown error. | 922| 14000002 | Invalid URI. | 923 924**Example** 925 926 ```ts 927 import { BusinessError } from '@kit.BasicServicesKit'; 928 import { fileUri } from '@kit.CoreFileKit'; 929 let path = "/data/storage/el2/cloud/1.txt"; 930 let uri = fileUri.getUriFromPath(path); 931 try { 932 let state = fileSync.getFileSyncState(uri) 933 }.catch(err) { 934 let error:BusinessError = err as BusinessError; 935 console.error("getFileSyncStatefailed with error:" + JSON.stringify(error)); 936 } 937 ``` 938 939## FileSyncState<sup>11+</sup> 940 941Enumerates the device-cloud file sync states. 942 943**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 944 945**System API**: This is a system API. 946 947| Name| Value| Description| 948| ----- | ---- | ---- | 949| UPLOADING | 0 | The file is being uploaded.| 950| DOWNLOADING | 1 | The file is being downloaded.| 951| COMPLETED | 2 | Sync completed.| 952| STOPPED | 3 | Sync stopped.| 953| TO_BE_UPLOADED<sup>12+</sup> | 4 | The file is going to be uploaded.| 954| UPLOAD_SUCCESS<sup>12+</sup> | 5 | The file has been successfully uploaded.| 955| UPLOAD_FAILURE<sup>12+</sup> | 6 | The file fails to be uploaded.| 956