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 '@ohos.file.cloudSync'; 14``` 15 16## SyncState 17 18Enumerates the device-cloud sync states. 19 20> **NOTE** 21> 22> If a sync progress event listener is registered for an application, a callback will be invoked to notify the application when the device-cloud sync state is changed. 23 24**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 25 26**System API**: This is a system API. 27 28| Name| Value| Description| 29| ----- | ---- | ---- | 30| UPLOADING | 0 | Uploading.| 31| UPLOAD_FAILED | 1 | Upload failed.| 32| DOWNLOADING | 2 | Downloading.| 33| DOWNLOAD_FAILED | 3 | Download failed.| 34| COMPLETED | 4 | Sync completed.| 35| STOPPED | 5 | Sync stopped.| 36 37## ErrorType 38 39Enumerates the device-cloud sync errors. 40 41- Currently, **NETWORK_UNAVAILABLE** is returned only when both the mobile network and Wi-Fi are unavailable during sync. If either network is available, sync can be performed normally. 42- During the sync process, if the battery level is lower than 15% in non-charging scenarios, **BATTERY_LEVEL_LOW** will be return when the current upload is complete; if the battery level is lower than 10% in non-charging scenarios, **BATTERY_LEVEL_WARNING** will be returned when the current upload is complete. 43- When sync is being triggered, if the battery level is lower than 15% in non-charging scenarios, sync is not allowed and an error code will be returned by **start()**. 44- If the cloud space is insufficient when a file is uploaded, the upload will fail and there is no such a file in the cloud. 45- If the local space is insufficient when a file is downloaded, the download will fail. After the local space is released, the file will be downloaded again when sync starts. 46 47**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 48 49**System API**: This is a system API. 50 51| Name| Value| Description| 52| ----- | ---- | ---- | 53| NO_ERROR | 0 | No error.| 54| NETWORK_UNAVAILABLE | 1 | No network is available.| 55| WIFI_UNAVAILABLE | 2 | Wi-Fi is unavailable.| 56| BATTERY_LEVEL_LOW | 3 | The battery level is lower than 15%.| 57| BATTERY_LEVEL_WARNING | 4 | The battery level is lower than 10%.| 58| CLOUD_STORAGE_FULL | 5 | The cloud space is insufficient.| 59| LOCAL_STORAGE_FULL | 6 | The local space is insufficient.| 60| DEVICE_TEMPERATURE_TOO_HIGH<sup>12+</sup> | 7 | The device temperature is too high.| 61 62## SyncProgress 63 64Represents information about the device-cloud sync progress. 65 66**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 67 68**System API**: This is a system API. 69 70| Name | Type | Mandatory| Description| 71| ---------- | ------ | ---- | ---- | 72| state | [SyncState](#syncstate) | Yes | Device-cloud sync state.| 73| error | [ErrorType](#errortype) | Yes | Sync error.| 74 75## GallerySync 76 77Provides APIs to implement device-cloud sync of media assets in **Gallery**. Before using the APIs of **GallerySync**, you need to create a **GallerySync** instance. 78 79### constructor 80 81constructor() 82 83A constructor used to create a **GallerySync** instance. 84 85**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 86 87**System API**: This is a system API. 88 89**Example** 90 91 ```ts 92 let gallerySync = new cloudSync.GallerySync() 93 ``` 94 95### on 96 97on(evt: 'progress', callback: (pg: SyncProgress) => void): void 98 99Registers a listener for the device-cloud sync progress. 100 101**Required permissions**: ohos.permission.CLOUDFILE_SYNC 102 103**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 104 105**System API**: This is a system API. 106 107**Parameters** 108 109| Name | Type | Mandatory| Description| 110| ---------- | ------ | ---- | ---- | 111| evt | string | Yes | Event type. The value is **progress**, which indicates the sync progress event.| 112| callback | (pg: SyncProgress) => void | Yes | Callback used to return the sync progress event. The input parameter is [SyncProgress](#syncprogress), and the return value is **void**.| 113 114**Error codes** 115 116For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 117 118| ID | Error Message | 119| ---------------------------- | ---------- | 120| 201 | Permission verification failed. | 121| 202 | The caller is not a system application. | 122| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 123| 13600001 | IPC error. | 124 125**Example** 126 127 ```ts 128 let gallerySync = new cloudSync.GallerySync(); 129 130 gallerySync.on('progress', (pg: cloudSync.SyncProgress) => { 131 console.info("syncState: " + pg.state); 132 }); 133 ``` 134 135### off 136 137off(evt: 'progress', callback: (pg: SyncProgress) => void): void 138 139Unregisters a listener for the device-cloud sync progress. 140 141**Required permissions**: ohos.permission.CLOUDFILE_SYNC 142 143**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 144 145**System API**: This is a system API. 146 147**Parameters** 148 149| Name | Type | Mandatory| Description| 150| ---------- | ------ | ---- | ---- | 151| evt | string | Yes | Event type. The value is **progress**, which indicates the sync progress event.| 152| callback | (pg: SyncProgress) => void | Yes | Callback to unregister. The input parameter is [SyncProgress](#syncprogress), and the return value is **void**.| 153 154**Error codes** 155 156For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 157 158| ID | Error Message | 159| ---------------------------- | ---------- | 160| 201 | Permission verification failed. | 161| 202 | The caller is not a system application. | 162| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 163| 13600001 | IPC error. | 164 165**Example** 166 167 ```ts 168 let gallerySync = new cloudSync.GallerySync(); 169 170 let callback = (pg: cloudSync.SyncProgress) => { 171 console.info("gallery sync state: " + pg.state + "error type:" + pg.error); 172 } 173 174 gallerySync.on('progress', callback); 175 176 gallerySync.off('progress', callback); 177 ``` 178 179### off 180 181off(evt: 'progress'): void 182 183Unregisters all listeners for the device-cloud sync progress. 184 185**Required permissions**: ohos.permission.CLOUDFILE_SYNC 186 187**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 188 189**System API**: This is a system API. 190 191**Parameters** 192 193| Name | Type | Mandatory| Description| 194| ---------- | ------ | ---- | ---- | 195| evt | string | Yes | Event type. The value is **progress**, which indicates the sync progress event.| 196 197**Error codes** 198 199For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 200 201| ID | Error Message | 202| ---------------------------- | ---------- | 203| 201 | Permission verification failed. | 204| 202 | The caller is not a system application. | 205| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 206| 13600001 | IPC error. | 207 208**Example** 209 210 ```ts 211 let gallerySync = new cloudSync.GallerySync(); 212 213 gallerySync.on('progress', (pg: cloudSync.SyncProgress) => { 214 console.info("syncState: " + pg.state); 215 }); 216 217 gallerySync.off('progress'); 218 ``` 219 220### start 221 222start(): Promise<void> 223 224Starts device-cloud sync. This API uses a promise to return the result. 225 226**Required permissions**: ohos.permission.CLOUDFILE_SYNC 227 228**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 229 230**System API**: This is a system API. 231 232**Return value** 233 234| Type | Description | 235| --------------------- | ---------------- | 236| Promise<void> | Promise used to return the result.| 237 238**Error codes** 239 240For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 241 242| ID | Error Message | 243| ---------------------------- | ---------- | 244| 201 | Permission verification failed. | 245| 202 | The caller is not a system application. | 246| 401 | The input parameter is invalid. Possible causes:Incorrect parameter types. | 247| 22400001 | Cloud status not ready. | 248| 22400002 | Network unavailable. | 249| 22400003 | Battery level warning. | 250 251**Example** 252 253 ```ts 254 import { BusinessError } from '@ohos.base'; 255 let gallerySync = new cloudSync.GallerySync(); 256 257 gallerySync.on('progress', (pg: cloudSync.SyncProgress) => { 258 console.info("syncState: " + pg.state); 259 }); 260 261 gallerySync.start().then(() => { 262 console.info("start sync successfully"); 263 }).catch((err: BusinessError) => { 264 console.error("start sync failed with error message: " + err.message + ", error code: " + err.code); 265 }); 266 ``` 267 268### start 269 270start(callback: AsyncCallback<void>): void 271 272Starts device-cloud sync. This API uses an asynchronous callback to return the result. 273 274**Required permissions**: ohos.permission.CLOUDFILE_SYNC 275 276**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 277 278**System API**: This is a system API. 279 280**Parameters** 281 282| Name | Type | Mandatory| Description| 283| ---------- | ------ | ---- | ---- | 284| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 285 286**Error codes** 287 288For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 289 290| ID | Error Message | 291| ---------------------------- | ---------- | 292| 201 | Permission verification failed. | 293| 202 | The caller is not a system application. | 294| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 295| 22400001 | Cloud status not ready. | 296| 22400002 | Network unavailable. | 297| 22400003 | Battery level warning. | 298 299**Example** 300 301 ```ts 302 import { BusinessError } from '@ohos.base'; 303 let gallerySync = new cloudSync.GallerySync(); 304 305 gallerySync.start((err: BusinessError) => { 306 if (err) { 307 console.error("start sync failed with error message: " + err.message + ", error code: " + err.code); 308 } else { 309 console.info("start sync successfully"); 310 } 311 }); 312 ``` 313 314### stop 315 316stop(): Promise<void> 317 318Stops device-cloud sync. This API uses a promise to return the result. 319 320> **NOTE** 321> 322> Calling **stop** will stop the sync process. To resume the sync, call [start](#start). 323 324**Required permissions**: ohos.permission.CLOUDFILE_SYNC 325 326**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 327 328**System API**: This is a system API. 329 330**Return value** 331 332| Type | Description | 333| --------------------- | ---------------- | 334| Promise<void> | Promise used to return the result.| 335 336**Error codes** 337 338For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 339 340| ID | Error Message | 341| ---------------------------- | ---------- | 342| 201 | Permission verification failed. | 343| 202 | The caller is not a system application. | 344| 401 | The input parameter is invalid. Possible causes:Incorrect parameter types. | 345 346**Example** 347 348 ```ts 349 import { BusinessError } from '@ohos.base'; 350 let gallerySync = new cloudSync.GallerySync(); 351 352 gallerySync.stop().then(() => { 353 console.info("stop sync successfully"); 354 }).catch((err: BusinessError) => { 355 console.error("stop sync failed with error message: " + err.message + ", error code: " + err.code); 356 }); 357 ``` 358 359### stop 360 361stop(callback: AsyncCallback<void>): void 362 363Stops device-cloud sync. This API uses an asynchronous callback to return the result. 364 365> **NOTE** 366> 367> Calling **stop** will stop the sync process. To resume the sync, call [start](#start). 368 369**Required permissions**: ohos.permission.CLOUDFILE_SYNC 370 371**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 372 373**System API**: This is a system API. 374 375**Parameters** 376 377| Name | Type | Mandatory| Description| 378| ---------- | ------ | ---- | ---- | 379| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 380 381**Error codes** 382 383For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 384 385| ID | Error Message | 386| ---------------------------- | ---------- | 387| 201 | Permission verification failed. | 388| 202 | The caller is not a system application. | 389| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 390 391**Example** 392 393 ```ts 394 import { BusinessError } from '@ohos.base'; 395 let gallerySync = new cloudSync.GallerySync(); 396 397 gallerySync.stop((err: BusinessError) => { 398 if (err) { 399 console.error("stop sync failed with error message: " + err.message + ", error code: " + err.code); 400 } else { 401 console.info("stop sync successfully"); 402 } 403 }); 404 ``` 405 406## Download 407 408Provides APIs for downloading image files to **Gallery**. Before using the APIs of **Download**, you need to create a **Download** instance. 409 410### constructor 411 412constructor() 413 414A constructor used to create a **Download** instance. 415 416**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 417 418**System API**: This is a system API. 419 420**Example** 421 422 ```ts 423 let download = new cloudSync.Download() 424 ``` 425 426### on 427 428on(evt: 'progress', callback: (pg: DownloadProgress) => void): void 429 430Registers a listener for the download progress of a cloud file. 431 432**Required permissions**: ohos.permission.CLOUDFILE_SYNC 433 434**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 435 436**System API**: This is a system API. 437 438**Parameters** 439 440| Name | Type | Mandatory| Description| 441| ---------- | ------ | ---- | ---- | 442| evt | string | Yes | Event. The value is **progress**, which indicates the download progress event of a cloud file.| 443| 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**.| 444 445**Error codes** 446 447For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 448 449| ID | Error Message | 450| ---------------------------- | ---------- | 451| 201 | Permission verification failed. | 452| 202 | The caller is not a system application. | 453| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 454| 13600001 | IPC error. | 455 456**Example** 457 458 ```ts 459 let download = new cloudSync.Download(); 460 461 download.on('progress', (pg: cloudSync.DownloadProgress) => { 462 console.info("download state: " + pg.state); 463 }); 464 ``` 465 466### off 467 468off(evt: 'progress', callback: (pg: DownloadProgress) => void): void 469 470Unregisters a listener for the download progress of a cloud file. 471 472**Required permissions**: ohos.permission.CLOUDFILE_SYNC 473 474**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 475 476**System API**: This is a system API. 477 478**Parameters** 479 480| Name | Type | Mandatory| Description| 481| ---------- | ------ | ---- | ---- | 482| evt | string | Yes | Event type. The value is **progress**, which indicates the sync progress event.| 483| 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**.| 484 485**Error codes** 486 487For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 488 489| ID | Error Message | 490| ---------------------------- | ---------- | 491| 201 | Permission verification failed. | 492| 202 | The caller is not a system application. | 493| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 494| 13600001 | IPC error. | 495 496**Example** 497 498 ```ts 499 let download = new cloudSync.Download(); 500 501 let callback = (pg: cloudSync.DownloadProgress) => { 502 console.info("download state: " + pg.state); 503 } 504 505 download.on('progress', callback); 506 507 download.off('progress', callback); 508 ``` 509 510### off 511 512off(evt: 'progress'): void 513 514Unregisters all listeners for the download progress event of a cloud file. 515 516**Required permissions**: ohos.permission.CLOUDFILE_SYNC 517 518**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 519 520**System API**: This is a system API. 521 522**Parameters** 523 524| Name | Type | Mandatory| Description| 525| ---------- | ------ | ---- | ---- | 526| evt | string | Yes | Event type. The value is **progress**, which indicates the download progress event of a cloud file.| 527 528**Error codes** 529 530For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 531 532| ID | Error Message | 533| ---------------------------- | ---------- | 534| 201 | Permission verification failed. | 535| 202 | The caller is not a system application. | 536| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 537| 13600001 | IPC error. | 538 539**Example** 540 541 ```ts 542 let download = new cloudSync.Download(); 543 544 download.on('progress', (pg: cloudSync.DownloadProgress) => { 545 console.info("download state:" + pg.state); 546 }); 547 548 download.off('progress'); 549 ``` 550 551### start 552 553start(uri: string): Promise<void> 554 555Starts to download a cloud file. This API uses a promise to return the result. 556 557**Required permissions**: ohos.permission.CLOUDFILE_SYNC 558 559**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 560 561**System API**: This is a system API. 562 563**Parameters** 564 565| Name | Type | Mandatory| Description| 566| ---------- | ------ | ---- | ---- | 567| uri | string | Yes | URI of the file to download.| 568 569**Return value** 570 571| Type | Description | 572| --------------------- | ---------------- | 573| Promise<void> | Promise used to return the result.| 574 575**Example** 576 577 ```ts 578 import { BusinessError } from '@ohos.base'; 579 let download = new cloudSync.Download(); 580 let uri: string = "file:///media/Photo/1"; 581 582 download.on('progress', (pg: cloudSync.DownloadProgress) => { 583 console.info("download state:" + pg.state); 584 }); 585 586 download.start(uri).then(() => { 587 console.info("start download successfully"); 588 }).catch((err: BusinessError) => { 589 console.error("start download failed with error message: " + err.message + ", error code: " + err.code); 590 }); 591 ``` 592 593**Error codes** 594 595For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 596 597| ID | Error Message | 598| ---------------------------- | ---------- | 599| 201 | Permission verification failed. | 600| 202 | The caller is not a system application. | 601| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 602| 13900002 | No such file or directory. | 603| 13900025 | No space left on device. | 604 605### start 606 607start(uri: string, callback: AsyncCallback<void>): void 608 609Starts to download a cloud file. This API uses an asynchronous callback to return the result. 610 611**Required permissions**: ohos.permission.CLOUDFILE_SYNC 612 613**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 614 615**System API**: This is a system API. 616 617**Parameters** 618 619| Name | Type | Mandatory| Description| 620| ---------- | ------ | ---- | ---- | 621| uri | string | Yes | URI of the file to download.| 622| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 623 624**Error codes** 625 626For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 627 628| ID | Error Message | 629| ---------------------------- | ---------- | 630| 201 | Permission verification failed. | 631| 202 | The caller is not a system application. | 632| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 633| 13900002 | No such file or directory. | 634| 13900025 | No space left on device. | 635 636**Example** 637 638 ```ts 639 import { BusinessError } from '@ohos.base'; 640 let download = new cloudSync.Download(); 641 let uri: string = "file:///media/Photo/1"; 642 643 download.start(uri, (err: BusinessError) => { 644 if (err) { 645 console.error("start download failed with error message: " + err.message + ", error code: " + err.code); 646 } else { 647 console.info("start download successfully"); 648 } 649 }); 650 ``` 651 652### stop 653 654stop(uri: string): Promise<void> 655 656Stops downloading a cloud file. This API uses a promise to return the result. 657 658> **NOTE** 659> 660> Calling **stop** will terminate the download of the current file and clear the cache file. You can use **start** to start the download again. 661 662**Required permissions**: ohos.permission.CLOUDFILE_SYNC 663 664**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 665 666**System API**: This is a system API. 667 668**Parameters** 669 670| Name | Type | Mandatory| Description| 671| ---------- | ------ | ---- | ---- | 672| uri | string | Yes | URI of the file to download.| 673 674**Return value** 675 676| Type | Description | 677| --------------------- | ---------------- | 678| Promise<void> | Promise used to return the result.| 679 680**Error codes** 681 682For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 683 684| ID | Error Message | 685| ---------------------------- | ---------- | 686| 201 | Permission verification failed. | 687| 202 | The caller is not a system application. | 688| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 689 690**Example** 691 692 ```ts 693 import { BusinessError } from '@ohos.base'; 694 let download = new cloudSync.Download(); 695 let uri: string = "file:///media/Photo/1"; 696 697 download.stop(uri).then(() => { 698 console.info("stop download successfully"); 699 }).catch((err: BusinessError) => { 700 console.error("stop download failed with error message: " + err.message + ", error code: " + err.code); 701 }); 702 ``` 703 704### stop 705 706stop(uri: string, callback: AsyncCallback<void>): void 707 708Stops downloading a cloud file. This API uses an asynchronous callback to return the result. 709 710> **NOTE** 711> 712> Calling **stop** will terminate the download of the current file and clear the cache file. You can use **start** to start the download again. 713 714**Required permissions**: ohos.permission.CLOUDFILE_SYNC 715 716**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 717 718**System API**: This is a system API. 719 720**Parameters** 721 722| Name | Type | Mandatory| Description| 723| ---------- | ------ | ---- | ---- | 724| uri | string | Yes | URI of the file to download.| 725| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 726 727**Error codes** 728 729For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 730 731| ID | Error Message | 732| ---------------------------- | ---------- | 733| 201 | Permission verification failed. | 734| 202 | The caller is not a system application. | 735| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 736 737**Example** 738 739 ```ts 740 import { BusinessError } from '@ohos.base'; 741 let download = new cloudSync.Download(); 742 let uri: string = "file:///media/Photo/1"; 743 744 download.stop(uri, (err: BusinessError) => { 745 if (err) { 746 console.error("stop download failed with error message: " + err.message + ", error code: " + err.code); 747 } else { 748 console.info("stop download successfully"); 749 } 750 }); 751 ``` 752 753## FileSync<sup>11+</sup> 754 755Provides 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. 756 757### constructor<sup>11+</sup> 758 759constructor() 760 761A constructor used to create a **FileSync** instance. 762 763**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 764 765**System API**: This is a system API. 766 767**Error codes** 768 769For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 770 771| ID | Error Message | 772| ---------------------------- | ---------- | 773| 202 | Permission verification failed, application which is not a system application uses system API. | 774| 401 | The input parameter is invalid. Possible causes:Incorrect parameter types. | 775 776**Example** 777 778 ```ts 779 let fileSync = new cloudSync.FileSync() 780 ``` 781 782### constructor<sup>12+</sup> 783 784constructor(bundleName: string) 785 786A constructor used to create a **FileSync** instance. 787 788**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 789 790**System API**: This is a system API. 791 792**Parameters** 793 794| Name | Type | Mandatory| Description| 795| ---------- | ------ | ---- | ---- | 796| bundleName | string | Yes | Application bundle name.| 797 798**Error codes** 799 800For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 801 802| ID | Error Message | 803| ---------------------------- | ---------- | 804| 202 | Permission verification failed, application which is not a system application uses system API. | 805| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 806 807**Example** 808 809 ```ts 810 let fileSync = new cloudSync.FileSync("com.ohos.demo") 811 ``` 812 813### on<sup>11+</sup> 814 815on(event: 'progress', callback: Callback\<SyncProgress>): void 816 817Registers a listener for the device-cloud sync progress. 818 819**Required permissions**: ohos.permission.CLOUDFILE_SYNC 820 821**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 822 823**System API**: This is a system API. 824 825**Parameters** 826 827| Name | Type | Mandatory| Description| 828| ---------- | ------ | ---- | ---- | 829| event | string | Yes | Event type. The value is **progress**, which indicates the sync progress event.| 830| callback | Callback\<[SyncProgress](#syncprogress)> | Yes | Callback used to return the sync progress information.| 831 832**Error codes** 833 834For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 835 836| ID | Error Message | 837| ---------------------------- | ---------- | 838| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 839| 202 | Permission verification failed, application which is not a system application uses system API. | 840| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 841| 13600001 | IPC error. | 842 843**Example** 844 845 ```ts 846 let fileSync = new cloudSync.FileSync(); 847 let callback = (pg: cloudSync.SyncProgress) => { 848 console.info("file sync state: " + pg.state + "error type:" + pg.error); 849 } 850 851 fileSync.on('progress', callback); 852 ``` 853 854### off<sup>11+</sup> 855 856off(event: 'progress', callback?: Callback\<SyncProgress>): void 857 858Unregisters a listener for the device-cloud sync progress. 859 860**Required permissions**: ohos.permission.CLOUDFILE_SYNC 861 862**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 863 864**System API**: This is a system API. 865 866**Parameters** 867 868| Name | Type | Mandatory| Description| 869| ---------- | ------ | ---- | ---- | 870| event | string | Yes | Event type. The value is **progress**, which indicates the sync progress event.| 871| callback | Callback\<[SyncProgress](#syncprogress)> | No | Callback for the sync progress event.| 872 873**Error codes** 874 875For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 876 877| ID | Error Message | 878| ---------------------------- | ---------- | 879| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 880| 202 | Permission verification failed, application which is not a system application uses system API. | 881| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 882| 13600001 | IPC error. | 883 884**Example** 885 886 ```ts 887 let fileSync = new cloudSync.FileSync(); 888 889 let callback = (pg: cloudSync.SyncProgress) => { 890 console.info("file sync state: " + pg.state + "error type:" + pg.error); 891 } 892 893 fileSync.on('progress', callback); 894 895 fileSync.off('progress', callback); 896 ``` 897 898### start<sup>11+</sup> 899 900start(): Promise<void> 901 902Starts device-cloud sync of a file in the Drive Kit. This API uses a promise to return the result. 903 904**Required permissions**: ohos.permission.CLOUDFILE_SYNC 905 906**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 907 908**System API**: This is a system API. 909 910**Return value** 911 912| Type | Description | 913| --------------------- | ---------------- | 914| Promise<void> | Promise that returns no value.| 915 916**Error codes** 917 918For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 919 920| ID | Error Message | 921| ---------------------------- | ---------- | 922| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 923| 202 | Permission verification failed, application which is not a system application uses system API. | 924| 401 | The input parameter is invalid. Possible causes:Incorrect parameter types. | 925| 13600001 | IPC error. | 926| 22400001 | Cloud status not ready. | 927| 22400002 | Network unavailable. | 928| 22400003 | Battery level warning. | 929 930**Example** 931 932 ```ts 933 import { BusinessError } from '@ohos.base'; 934 let fileSync = new cloudSync.FileSync(); 935 936 let callback = (pg: cloudSync.SyncProgress) => { 937 console.info("file sync state: " + pg.state + "error type:" + pg.error); 938 } 939 940 fileSync.on('progress', callback); 941 942 fileSync.start().then(() => { 943 console.info("start sync successfully"); 944 }).catch((err: BusinessError) => { 945 console.error("start sync failed with error message: " + err.message + ", error code: " + err.code); 946 }); 947 ``` 948 949### start<sup>11+</sup> 950 951start(callback: AsyncCallback<void>): void 952 953Starts device-cloud sync of a file in the Drive Kit. This API uses an asynchronous callback to return the result. 954 955**Required permissions**: ohos.permission.CLOUDFILE_SYNC 956 957**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 958 959**System API**: This is a system API. 960 961**Parameters** 962 963| Name | Type | Mandatory| Description| 964| ---------- | ------ | ---- | ---- | 965| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 966 967**Error codes** 968 969For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 970 971| ID | Error Message | 972| ---------------------------- | ---------- | 973| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 974| 202 | Permission verification failed, application which is not a system application uses system API. | 975| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 976| 13600001 | IPC error. | 977| 22400001 | Cloud status not ready. | 978| 22400002 | Network unavailable. | 979| 22400003 | Battery level warning. | 980 981**Example** 982 983 ```ts 984 import { BusinessError } from '@ohos.base'; 985 let fileSync = new cloudSync.FileSync(); 986 987 fileSync.start((err: BusinessError) => { 988 if (err) { 989 console.error("start sync failed with error message: " + err.message + ", error code: " + err.code); 990 } else { 991 console.info("start sync successfully"); 992 } 993 }); 994 ``` 995 996### stop<sup>11+</sup> 997 998stop(): Promise<void> 999 1000Stops device-cloud sync of the file in the Drive Kit. This API uses a promise to return the result. 1001 1002Calling **stop** will stop the sync process. To resume the sync, call [start](#start). 1003 1004**Required permissions**: ohos.permission.CLOUDFILE_SYNC 1005 1006**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1007 1008**System API**: This is a system API. 1009 1010**Return value** 1011 1012| Type | Description | 1013| --------------------- | ---------------- | 1014| Promise<void> | Promise used to return the result.| 1015 1016**Error codes** 1017 1018For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 1019 1020| ID | Error Message | 1021| ---------------------------- | ---------- | 1022| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1023| 202 | Permission verification failed, application which is not a system application uses system API. | 1024| 401 | The input parameter is invalid. Possible causes:Incorrect parameter types. | 1025| 13600001 | IPC error. | 1026 1027**Example** 1028 1029 ```ts 1030 import { BusinessError } from '@ohos.base'; 1031 let fileSync = new cloudSync.FileSync(); 1032 1033 fileSync.stop().then(() => { 1034 console.info("stop sync successfully"); 1035 }).catch((err: BusinessError) => { 1036 console.error("stop sync failed with error message: " + err.message + ", error code: " + err.code); 1037 }); 1038 ``` 1039 1040### stop<sup>11+</sup> 1041 1042stop(callback: AsyncCallback<void>): void 1043 1044Stops device-cloud sync of the file in the Drive Kit. This API uses an asynchronous callback to return the result. 1045 1046Calling **stop** will stop the sync process. To resume the sync, call [start](#start). 1047 1048**Required permissions**: ohos.permission.CLOUDFILE_SYNC 1049 1050**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1051 1052**System API**: This is a system API. 1053 1054**Parameters** 1055 1056| Name | Type | Mandatory| Description| 1057| ---------- | ------ | ---- | ---- | 1058| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 1059 1060**Error codes** 1061 1062For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 1063 1064| ID | Error Message | 1065| ---------------------------- | ---------- | 1066| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1067| 202 | Permission verification failed, application which is not a system application uses system API. | 1068| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1069| 13600001 | IPC error. | 1070 1071**Example** 1072 1073 ```ts 1074 import { BusinessError } from '@ohos.base'; 1075 let fileSync = new cloudSync.FileSync(); 1076 1077 fileSync.stop((err: BusinessError) => { 1078 if (err) { 1079 console.error("stop sync failed with error message: " + err.message + ", error code: " + err.code); 1080 } else { 1081 console.info("stop sync successfully"); 1082 } 1083 }); 1084 ``` 1085 1086### getLastSyncTime<sup>11+</sup> 1087 1088getLastSyncTime(): Promise<number> 1089 1090Obtains the last sync time. This API uses a promise to return the result. 1091 1092**Required permissions**: ohos.permission.CLOUDFILE_SYNC 1093 1094**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1095 1096**System API**: This is a system API. 1097 1098**Return value** 1099 1100| Type | Description | 1101| --------------------- | ---------------- | 1102| Promise<number> | Promise used to return the last sync time obtained.| 1103 1104**Error codes** 1105 1106For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 1107 1108| ID | Error Message | 1109| ---------------------------- | ---------- | 1110| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1111| 202 | Permission verification failed, application which is not a system application uses system API. | 1112| 401 | The input parameter is invalid. Possible causes:Incorrect parameter types. | 1113| 13600001 | IPC error. | 1114 1115**Example** 1116 1117 ```ts 1118 import { BusinessError } from '@ohos.base'; 1119 let fileSync = new cloudSync.FileSync(); 1120 1121 fileSync.getLastSyncTime().then((timeStamp: number) => { 1122 let date = new Date(timeStamp); 1123 console.info("get last sync time successfully:"+ date); 1124 }).catch((err: BusinessError) => { 1125 console.error("get last sync time failed with error message: " + err.message + ", error code: " + err.code); 1126 }); 1127 1128 ``` 1129 1130### getLastSyncTime<sup>11+</sup> 1131 1132getLastSyncTime(callback: AsyncCallback<number>): void; 1133 1134Obtains the last sync time. This API uses an asynchronous callback to return the result. 1135 1136**Required permissions**: ohos.permission.CLOUDFILE_SYNC 1137 1138**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1139 1140**System API**: This is a system API. 1141 1142**Parameters** 1143 1144| Name | Type | Mandatory| Description| 1145| ---------- | ------ | ---- | ---- | 1146| callback | AsyncCallback<number> | Yes | Callback used to return the last sync time obtained.| 1147 1148**Error codes** 1149 1150For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 1151 1152| ID | Error Message | 1153| ---------------------------- | ---------- | 1154| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1155| 202 | Permission verification failed, application which is not a system application uses system API. | 1156| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1157| 13600001 | IPC error. | 1158 1159**Example** 1160 1161 ```ts 1162 import { BusinessError } from '@ohos.base'; 1163 let fileSync = new cloudSync.FileSync(); 1164 1165 fileSync.getLastSyncTime((err: BusinessError, timeStamp: number) => { 1166 if (err) { 1167 console.error("get last sync time with error message: " + err.message + ", error code: " + err.code); 1168 } else { 1169 let date = new Date(timeStamp); 1170 console.info("get last sync time successfully:"+ date); 1171 } 1172 }); 1173 ``` 1174 1175## CloudFileCache<sup>11+</sup> 1176 1177Provides APIs for the file manager application to download files from the Drive Kit to a local device. 1178 1179**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1180 1181### cleanCache<sup>11+</sup> 1182 1183cleanCache(uri: string): void; 1184 1185Deletes a cache file. This API returns the result synchronously. 1186 1187**Required permissions**: ohos.permission.CLOUDFILE_SYNC 1188 1189**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1190 1191**System API**: This is a system API. 1192 1193**Parameters** 1194 1195| Name | Type | Mandatory| Description| 1196| ---------- | ------ | ---- | ---- | 1197| uri | string | Yes | URI of the cache file to delete.| 1198 1199**Error codes** 1200 1201For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 1202 1203| ID | Error Message | 1204| ---------------------------- | ---------- | 1205| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1206| 202 | Permission verification failed, application which is not a system application uses system API. | 1207| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1208| 13600001 | IPC error. | 1209| 13900002 | No such file or directory. | 1210| 14000002 | Invalid uri. | 1211 1212**Example** 1213 1214 ```ts 1215 import { BusinessError } from '@ohos.base'; 1216 import fileUri from '@ohos.file.fileuri'; 1217 let fileCache = new cloudSync.CloudFileCache(); 1218 let path = "/data/storage/el2/cloud/1.txt"; 1219 let uri = fileUri.getUriFromPath(path); 1220 1221 try { 1222 fileCache.cleanCache(uri); 1223 } catch (err) { 1224 let error:BusinessError = err as BusinessError; 1225 console.error("clean cache failed with error message: " + err.message + ", error code: " + err.code); 1226 } 1227 1228 ``` 1229 1230## cloudSync.getFileSyncState<sup>11+</sup> 1231 1232getFileSyncState(uri: Array<string>): Promise<Array<FileSyncState>> 1233 1234Obtains the file sync state. This API uses a promise to return the result. 1235 1236**Required permissions**: ohos.permission.CLOUDFILE_SYNC 1237 1238**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1239 1240**System API**: This is a system API. 1241 1242**Parameters** 1243 1244| Name | Type | Mandatory| Description| 1245| ---------- | ------ | ---- | ---- | 1246| uri | Array<string> | Yes | URI of the file whose sync state is to be obtained.| 1247 1248**Return value** 1249 1250| Type | Description | 1251| --------------------- | ---------------- | 1252| Promise<Array<FileSyncState>> | Promise used to return the sync state obtained.| 1253 1254**Error codes** 1255 1256For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 1257 1258| ID | Error Message | 1259| ---------------------------- | ---------- | 1260| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1261| 202 | Permission verification failed, application which is not a system application uses system API. | 1262| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1263| 13600001 | IPC error. | 1264| 13900002 | No such file or directory. | 1265| 14000002 | Invalid uri. | 1266 1267**Example** 1268 1269 ```ts 1270 import { BusinessError } from '@ohos.base'; 1271 1272 let uris: Array<string> = ["file://uri"]; 1273 cloudSync.getFileSyncState(uris).then(function(syncStates: Array<cloudSync.FileSyncState>) { 1274 for(let i = 0, len = syncStates.length; i < len; i++){ 1275 console.info("get file sync state successfully" + syncStates[i]); 1276 } 1277 }).catch((err: BusinessError) => { 1278 console.error("get file sync state failed with error message: " + err.message + ", error code: " + err.code); 1279 }); 1280 1281 ``` 1282 1283## cloudSync.getFileSyncState<sup>11+</sup> 1284 1285getFileSyncState(uri: Array<string>, callback: AsyncCallback<Array<FileSyncState>>): void 1286 1287Obtains the file sync state. This API uses an asynchronous callback to return the result. 1288 1289**Required permissions**: ohos.permission.CLOUDFILE_SYNC 1290 1291**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1292 1293**System API**: This is a system API. 1294 1295**Parameters** 1296 1297| Name | Type | Mandatory| Description| 1298| ---------- | ------ | ---- | ---- | 1299| uri | Array<string> | Yes | URI of the file whose sync state is to be obtained.| 1300| callback | AsyncCallback<Array<FileSyncState>> | Yes | Callback used to return the file sync state.| 1301 1302**Error codes** 1303 1304For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 1305 1306| ID | Error Message | 1307| ---------------------------- | ---------- | 1308| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1309| 202 | Permission verification failed, application which is not a system application uses system API. | 1310| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1311| 13600001 | IPC error. | 1312| 13900002 | No such file or directory. | 1313| 14000002 | Invalid uri. | 1314 1315**Example** 1316 1317 ```ts 1318 import { BusinessError } from '@ohos.base'; 1319 1320 let uris: Array<string> = ["file://uri"]; 1321 cloudSync.getFileSyncState(uris, (err: BusinessError, syncStates: Array<cloudSync.FileSyncState>) => { 1322 if (err) { 1323 console.error("get file sync state with error message: " + err.message + ", error code: " + err.code); 1324 } else { 1325 for(let i = 0, len = syncStates.length; i < len; i++){ 1326 console.info("get file sync state successfully" + syncStates[i]); 1327 } 1328 } 1329 }); 1330 ``` 1331 1332## cloudSync.getFileSyncState<sup>12+</sup> 1333 1334getFileSyncState(uri: string): FileSyncState 1335 1336Obtains the file sync status. 1337 1338**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1339 1340**System API**: This is a system API. 1341 1342**Parameters** 1343 1344| Name | Type | Mandatory| Description| 1345| ---------- | ------ | ---- | ---- | 1346| uri | string | Yes | URI of the target file.| 1347 1348**Return value** 1349 1350| Type | Description | 1351| --------------------- | ---------------- | 1352| [FileSyncState](#filesyncstate11) | Sync status of the file.| 1353 1354**Error codes** 1355 1356For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 1357 1358| ID | Error Message | 1359| ---------------------------- | ---------- | 1360| 202 | Permission verification failed, application which is not a system application uses system API. | 1361| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1362| 13900002 | No such file or directory. | 1363| 13900004 | Interrupted system call. | 1364| 13900010 | Try again. | 1365| 13900012 | Permission denied by the file system. | 1366| 13900031 | Function not implemented. | 1367| 13900042 | Unknown error. | 1368| 14000002 | Invalid uri. | 1369 1370**Example** 1371 1372 ```ts 1373 import { BusinessError } from '@ohos.base'; 1374 import fileUri from '@ohos.file.fileuri'; 1375 let path = "/data/storage/el2/cloud/1.txt"; 1376 let uri = fileUri.getUriFromPath(path); 1377 try { 1378 let state = fileSync.getFileSyncState(uri) 1379 }.catch(err) { 1380 let error:BusinessError = err as BusinessError; 1381 console.error("getFileSyncStatefailed with error:" + JSON.stringify(error)); 1382 } 1383 ``` 1384 1385## cloudSync.registerChange<sup>12+</sup> 1386 1387registerChange(uri: string, recursion: boolean, callback: Callback<ChangeData>): void 1388 1389Subscribes to the change of a file. 1390 1391**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1392 1393**System API**: This is a system API. 1394 1395**Parameters** 1396 1397| Name | Type | Mandatory| Description| 1398| ---------- | ------ | ---- | ---- | 1399| uri | string | Yes | URI of the target file.| 1400| recursion | boolean | Yes | Whether to subscribe to the change of the sub-folders and files of the given URI. The value **true** means to subscribe to the change of the sub-folders and files of the given URI; the value **false** means to subscribe to only the change of the given URI.| 1401| callback | Callback<[ChangeData](#changedata12)> | Yes | Callback used to return the changed data.| 1402 1403**Error codes** 1404 1405For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 1406 1407| ID | Error Message | 1408| ---------------------------- | ---------- | 1409| 202 | Permission verification failed, application which is not a system application uses system API. | 1410| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1411| 13900001 | Operation not permitted. | 1412| 13900002 | No such file or directory. | 1413| 13900012 | Permission denied. | 1414| 14000002 | Invalid uri. | 1415 1416**Example** 1417 1418 ```ts 1419 import fileUri from '@ohos.file.fileuri'; 1420 let path = "/data/storage/el2/cloud/1.txt"; 1421 let uri = fileUri.getUriFromPath(path); 1422 let onCallback1 = (changeData: ChangeData) => { 1423 if (changeData.type == cloudSync.NotifyType.NOTIFY_ADDED) { 1424 //file had added, do something 1425 } else if (changeData.type== cloudSync.NotifyType.NOTIFY_DELETED) { 1426 //file had removed, do something 1427 } 1428 } 1429 cloudSync.registerChange(uri, false, onCallback1); 1430 // Unregister the listener. 1431 cloudSync.unRegisterChange(uri); 1432 ``` 1433 1434## cloudSync.unregisterChange<sup>12+</sup> 1435 1436unregisterChange(uri: string): void 1437 1438Unsubscribes from the change of a file. 1439 1440**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1441 1442**System API**: This is a system API. 1443 1444**Parameters** 1445 1446| Name | Type | Mandatory| Description| 1447| ---------- | ------ | ---- | ---- | 1448| uri | string | Yes | URI of the target file.| 1449 1450**Error codes** 1451 1452For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md). 1453 1454| ID | Error Message | 1455| ---------------------------- | ---------- | 1456| 202 | Permission verification failed, application which is not a system application uses system API. | 1457| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1458| 13900001 | Operation not permitted. | 1459| 13900002 | No such file or directory. | 1460| 13900012 | Permission denied. | 1461| 14000002 | Invalid uri. | 1462 1463**Example** 1464 1465 ```ts 1466 import fileUri from '@ohos.file.fileuri'; 1467 let path = "/data/storage/el2/cloud/1.txt"; 1468 let uri = fileUri.getUriFromPath(path); 1469 let onCallback1 = (changeData: ChangeData) => { 1470 if (changeData.type == cloudSync.NotifyType.NOTIFY_ADDED) { 1471 //file had added, do something 1472 } else if (changeData.type== cloudSync.NotifyType.NOTIFY_DELETED) { 1473 //file had removed, do something 1474 } 1475 } 1476 cloudSync.registerChange(uri, false, onCallback1); 1477 // Unregister the listener. 1478 cloudSync.unRegisterChange(uri); 1479 ``` 1480 1481## NotifyType<sup>12+</sup> 1482 1483Enumerates the data change types. 1484 1485**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1486 1487**System API**: This is a system API. 1488 1489| Name| Value| Description| 1490| ----- | ---- | ---- | 1491| NOTIFY_ADDED | 0 | A file is created.| 1492| NOTIFY_MODIFIED | 1 | The file is modified.| 1493| NOTIFY_DELETED | 2 | The file is deleted.| 1494| NOTIFY_RENAMED | 3 | The file is renamed or moved.| 1495 1496## ChangeData<sup>12+</sup> 1497 1498Represents the data change information. 1499 1500**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1501 1502**System API**: This is a system API. 1503 1504| Name | Type | Mandatory| Description| 1505| ---------- | ------ | ---- | ---- | 1506| type | [NotifyType](#notifytype12) | Yes | Type of the data change.| 1507| isDirectory | Array<boolean> | Yes | Whether the URIs with data changed are of folders.| 1508| uris | Array<string> | Yes | URIs of the files changed.| 1509 1510## FileSyncState<sup>11+</sup> 1511 1512Enumerates the device-cloud file sync states. 1513 1514**System capability**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1515 1516**System API**: This is a system API. 1517 1518| Name| Value| Description| 1519| ----- | ---- | ---- | 1520| UPLOADING | 0 | The file is being uploaded.| 1521| DOWNLOADING | 1 | The file is being downloaded.| 1522| COMPLETED | 2 | The file sync is complete.| 1523| STOPPED | 3 | The file sync is stopped.| 1524| TO_BE_UPLOADED<sup>12+</sup> | 4 | The file is to be uploaded.| 1525| UPLOAD_SUCCESS<sup>12+</sup> | 5 | The file is uploaded successfully.| 1526| UPLOAD_FAILURE<sup>12+</sup> | 6 | The upload fails.| 1527