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