• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.file.cloudSync (端云同步能力)(系统接口)
2
3该模块向应用提供端云同步能力,包括启动/停止端云同步以及启动/停止原图下载功能。
4
5> **说明:**
6>
7> - 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8> - 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.file.cloudSync (端云同步能力)](js-apis-file-cloudsync.md)。
9
10## 导入模块
11
12```ts
13import cloudSync from '@ohos.file.cloudSync';
14```
15
16## SyncState
17
18端云同步状态,为枚举类型。
19
20> **说明:**
21>
22> 以下同步状态发生变更时,如果应用注册了同步过程事件监听,则通过回调通知应用。
23
24**系统能力**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
25
26**系统接口:** 该接口为系统接口。
27
28| 名称 |  值|  说明 |
29| ----- |  ---- |  ---- |
30| UPLOADING |  0 | 上行同步中 |
31| UPLOAD_FAILED |  1 | 上行同步失败 |
32| DOWNLOADING |  2 | 下行同步中 |
33| DOWNLOAD_FAILED |  3 | 下行同步失败 |
34| COMPLETED |  4 | 同步成功 |
35| STOPPED |  5 | 同步已停止 |
36
37## ErrorType
38
39端云同步失败类型,为枚举类型。
40
41- 当前阶段,同步过程中,当移动数据网络和WIFI均不可用时,才会返回NETWORK_UNAVAILABLE;若有一种类型网络可用,则能正常同步。
42- 同步过程中,非充电场景下,电量低于15%,完成当前批上行同步后停止同步,返回低电量;电量低于10%,完成当前批上行同步后停止同步,返回告警电量。
43- 触发同步时,非充电场景下,若电量低于15%,则不允许同步,start接口返回对应错误。
44- 上行时,若云端空间不足,则文件上行失败,云端无该文件记录。
45- 下行时,若本地空间不足,则文件下行失败,本地空间释放后再次同步会重新下行。
46
47**系统能力**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
48
49**系统接口:** 该接口为系统接口。
50
51| 名称 |  值|  说明 |
52| ----- |  ---- |  ---- |
53| NO_ERROR |  0 | 没有错误 |
54| NETWORK_UNAVAILABLE |  1 | 所有网络不可用 |
55| WIFI_UNAVAILABLE |  2 | WIFI不可用 |
56| BATTERY_LEVEL_LOW |  3 | 低电量(低于15%) |
57| BATTERY_LEVEL_WARNING |  4 | 告警电量(低于10%) |
58| CLOUD_STORAGE_FULL |  5 | 云端空间不足 |
59| LOCAL_STORAGE_FULL |  6 | 本地空间不足 |
60
61## SyncProgress
62
63端云同步过程。
64
65**系统能力**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
66
67**系统接口:** 该接口为系统接口。
68
69| 名称     | 类型   | 必填 | 说明 |
70| ---------- | ------ | ---- | ---- |
71| state | [SyncState](#syncstate) | 是   | 枚举值,端云同步状态|
72| error | [ErrorType](#errortype) | 是   | 枚举值,同步失败错误类型|
73
74## GallerySync
75
76云图同步对象,用来支撑图库应用媒体资源端云同步流程。在使用前,需要先创建GallerySync实例。
77
78### constructor
79
80constructor()
81
82端云同步流程的构造函数,用于获取GallerySync类的实例。
83
84**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
85
86**系统接口:** 该接口为系统接口。
87
88**示例:**
89
90  ```ts
91  let gallerySync = new cloudSync.GallerySync()
92  ```
93
94### on
95
96on(evt: 'progress', callback: (pg: SyncProgress) => void): void
97
98添加同步过程事件监听。
99
100**需要权限**:ohos.permission.CLOUDFILE_SYNC
101
102**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
103
104**系统接口:** 该接口为系统接口。
105
106**参数:**
107
108| 参数名     | 类型   | 必填 | 说明 |
109| ---------- | ------ | ---- | ---- |
110| evt | string | 是   | 订阅的事件类型,取值为'progress'(同步过程事件) |
111| callback | (pg: SyncProgress) => void | 是   | 同步过程事件回调,回调入参为[SyncProgress](#syncprogress), 返回值为void|
112
113**错误码:**
114
115以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
116
117| 错误码ID                     | 错误信息        |
118| ---------------------------- | ---------- |
119| 201 | Permission verification failed. |
120| 202 | The caller is not a system application. |
121| 401 | The input parameter is invalid. |
122| 13600001  | IPC error. |
123
124**示例:**
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
138移除同步过程事件监听。
139
140**需要权限**:ohos.permission.CLOUDFILE_SYNC
141
142**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
143
144**系统接口:** 该接口为系统接口。
145
146**参数:**
147
148| 参数名     | 类型   | 必填 | 说明 |
149| ---------- | ------ | ---- | ---- |
150| evt | string | 是   | 取消订阅的事件类型,取值为'progress'(同步过程事件)|
151| callback | (pg: SyncProgress) => void | 是   | 同步过程事件回调,回调入参为[SyncProgress](#syncprogress), 返回值为void|
152
153**错误码:**
154
155以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
156
157| 错误码ID                     | 错误信息        |
158| ---------------------------- | ---------- |
159| 201 | Permission verification failed. |
160| 202 | The caller is not a system application. |
161| 401 | The input parameter is invalid. |
162| 13600001  | IPC error. |
163
164**示例:**
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
182移除同步过程事件监听。
183
184**需要权限**:ohos.permission.CLOUDFILE_SYNC
185
186**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
187
188**系统接口:** 该接口为系统接口。
189
190**参数:**
191
192| 参数名     | 类型   | 必填 | 说明 |
193| ---------- | ------ | ---- | ---- |
194| evt | string | 是   | 取消订阅的事件类型,取值为'progress'(同步过程事件)|
195
196**错误码:**
197
198以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
199
200| 错误码ID                     | 错误信息        |
201| ---------------------------- | ---------- |
202| 201 | Permission verification failed. |
203| 202 | The caller is not a system application. |
204| 401 | The input parameter is invalid. |
205| 13600001  | IPC error. |
206
207**示例:**
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<void>
222
223异步方法启动端云同步, 以Promise形式返回结果。
224
225**需要权限**:ohos.permission.CLOUDFILE_SYNC
226
227**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
228
229**系统接口:** 该接口为系统接口。
230
231**返回值:**
232
233| 类型                  | 说明             |
234| --------------------- | ---------------- |
235| Promise<void> | 使用Promise形式返回启动端云同步的结果 |
236
237**错误码:**
238
239以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
240
241| 错误码ID                     | 错误信息        |
242| ---------------------------- | ---------- |
243| 201 | Permission verification failed. |
244| 202 | The caller is not a system application. |
245| 401 | The input parameter is invalid. |
246| 22400001 | Cloud status not ready. |
247| 22400002 | Network unavailable. |
248| 22400003  | Battery level warning. |
249
250**示例:**
251
252  ```ts
253  import { BusinessError } from '@ohos.base';
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.info("start sync failed with error message: " + err.message + ", error code: " + err.code);
264  });
265  ```
266
267### start
268
269start(callback: AsyncCallback<void>): void
270
271异步方法启动端云同步, 以callback形式返回结果。
272
273**需要权限**:ohos.permission.CLOUDFILE_SYNC
274
275**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
276
277**系统接口:** 该接口为系统接口。
278
279**参数:**
280
281| 参数名     | 类型   | 必填 | 说明 |
282| ---------- | ------ | ---- | ---- |
283| callback | AsyncCallback<void> | 是   | 异步启动端云同步的回调 |
284
285**错误码:**
286
287以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
288
289| 错误码ID                     | 错误信息        |
290| ---------------------------- | ---------- |
291| 201 | Permission verification failed. |
292| 202 | The caller is not a system application. |
293| 401 | The input parameter is invalid. |
294| 22400001 | Cloud status not ready. |
295| 22400002 | Network unavailable. |
296| 22400003  | Battery level warning. |
297
298**示例:**
299
300  ```ts
301  import { BusinessError } from '@ohos.base';
302  let gallerySync = new cloudSync.GallerySync();
303
304  gallerySync.start((err: BusinessError) => {
305    if (err) {
306      console.info("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<void>
316
317异步方法停止端云同步, 以Promise形式返回结果。
318
319> **说明:**
320>
321> 调用stop接口,同步流程会停止。再次调用[start](#start)接口会继续同步。
322
323**需要权限**:ohos.permission.CLOUDFILE_SYNC
324
325**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
326
327**系统接口:** 该接口为系统接口。
328
329**返回值:**
330
331| 类型                  | 说明             |
332| --------------------- | ---------------- |
333| Promise<void> | 使用Promise形式返回停止端云同步的结果 |
334
335**错误码:**
336
337以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
338
339| 错误码ID                     | 错误信息        |
340| ---------------------------- | ---------- |
341| 201 | Permission verification failed. |
342| 202 | The caller is not a system application. |
343| 401 | The input parameter is invalid. |
344
345**示例:**
346
347  ```ts
348  import { BusinessError } from '@ohos.base';
349  let gallerySync = new cloudSync.GallerySync();
350
351  gallerySync.stop().then(() => {
352	  console.info("stop sync successfully");
353  }).catch((err: BusinessError) => {
354	  console.info("stop sync failed with error message: " + err.message + ", error code: " + err.code);
355  });
356  ```
357
358### stop
359
360stop(callback: AsyncCallback<void>): void
361
362异步方法停止端云同步, 以callback形式返回结果。
363
364> **说明:**
365>
366> 调用stop接口,同步流程会停止。再次调用[start](#start)接口会继续同步。
367
368**需要权限**:ohos.permission.CLOUDFILE_SYNC
369
370**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
371
372**系统接口:** 该接口为系统接口。
373
374**参数:**
375
376| 参数名     | 类型   | 必填 | 说明 |
377| ---------- | ------ | ---- | ---- |
378| callback | AsyncCallback<void> | 是   | 异步停止端云同步的回调 |
379
380**错误码:**
381
382以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
383
384| 错误码ID                     | 错误信息        |
385| ---------------------------- | ---------- |
386| 201 | Permission verification failed. |
387| 202 | The caller is not a system application. |
388| 401 | The input parameter is invalid. |
389
390**示例:**
391
392  ```ts
393  import { BusinessError } from '@ohos.base';
394  let gallerySync = new cloudSync.GallerySync();
395
396  gallerySync.stop((err: BusinessError) => {
397    if (err) {
398      console.info("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
407云文件下载对象,用来支撑图库应用原图文件下载流程。在使用前,需要先创建Download实例。
408
409### constructor
410
411constructor()
412
413云文件下载流程的构造函数,用于获取Download类的实例。
414
415**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
416
417**系统接口:** 该接口为系统接口。
418
419**示例:**
420
421  ```ts
422  let download = new cloudSync.Download()
423  ```
424
425### on
426
427on(evt: 'progress', callback: (pg: DownloadProgress) => void): void
428
429添加云文件下载过程事件监听。
430
431**需要权限**:ohos.permission.CLOUDFILE_SYNC
432
433**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
434
435**系统接口:** 该接口为系统接口。
436
437**参数:**
438
439| 参数名     | 类型   | 必填 | 说明 |
440| ---------- | ------ | ---- | ---- |
441| evt | string | 是   | 订阅的事件类型,取值为'progress'(下载过程事件)|
442| callback | (pg: DownloadProgress) => void | 是   | 云文件下载过程事件回调,回调入参为[DownloadProgress](js-apis-file-cloudsync.md#downloadprogress11), 返回值为void|
443
444**错误码:**
445
446以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
447
448| 错误码ID                     | 错误信息        |
449| ---------------------------- | ---------- |
450| 201 | Permission verification failed. |
451| 202 | The caller is not a system application. |
452| 401 | The input parameter is invalid. |
453| 13600001  | IPC error. |
454
455**示例:**
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
469移除云文件下载过程事件监听。
470
471**需要权限**:ohos.permission.CLOUDFILE_SYNC
472
473**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
474
475**系统接口:** 该接口为系统接口。
476
477**参数:**
478
479| 参数名     | 类型   | 必填 | 说明 |
480| ---------- | ------ | ---- | ---- |
481| evt | string | 是   | 取消订阅的事件类型,取值为'progress'(同步过程事件)|
482| callback | (pg: DownloadProgress) => void | 是   | 云文件下载过程事件回调,回调入参为[DownloadProgress](js-apis-file-cloudsync.md#downloadprogress11), 返回值为void|
483
484**错误码:**
485
486以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
487
488| 错误码ID                     | 错误信息        |
489| ---------------------------- | ---------- |
490| 201 | Permission verification failed. |
491| 202 | The caller is not a system application. |
492| 401 | The input parameter is invalid. |
493| 13600001  | IPC error. |
494
495**示例:**
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
513移除云文件下载过程事件监听。
514
515**需要权限**:ohos.permission.CLOUDFILE_SYNC
516
517**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
518
519**系统接口:** 该接口为系统接口。
520
521**参数:**
522
523| 参数名     | 类型   | 必填 | 说明 |
524| ---------- | ------ | ---- | ---- |
525| evt | string | 是   | 取消订阅的事件类型,取值为'progress'(下载过程事件)|
526
527**错误码:**
528
529以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
530
531| 错误码ID                     | 错误信息        |
532| ---------------------------- | ---------- |
533| 201 | Permission verification failed. |
534| 202 | The caller is not a system application. |
535| 401 | The input parameter is invalid. |
536| 13600001  | IPC error. |
537
538**示例:**
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<void>
553
554异步方法启动云文件下载, 以Promise形式返回结果。
555
556**需要权限**:ohos.permission.CLOUDFILE_SYNC
557
558**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
559
560**系统接口:** 该接口为系统接口。
561
562**参数:**
563
564| 参数名     | 类型   | 必填 | 说明 |
565| ---------- | ------ | ---- | ---- |
566| uri | string | 是   | 待下载文件uri |
567
568**返回值:**
569
570| 类型                  | 说明             |
571| --------------------- | ---------------- |
572| Promise<void> | 使用Promise形式返回启动云文件下载的结果 |
573
574**示例:**
575
576  ```ts
577  import { BusinessError } from '@ohos.base';
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.info("start download failed with error message: " + err.message + ", error code: " + err.code);
589  });
590  ```
591
592**错误码:**
593
594以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
595
596| 错误码ID                     | 错误信息        |
597| ---------------------------- | ---------- |
598| 201 | Permission verification failed. |
599| 202 | The caller is not a system application. |
600| 401 | The input parameter is invalid. |
601| 13900002 | No such file or directory. |
602| 13900025 | No space left on device. |
603
604### start
605
606start(uri: string, callback: AsyncCallback<void>): void
607
608异步方法启动云文件下载, 以callback形式返回结果。
609
610**需要权限**:ohos.permission.CLOUDFILE_SYNC
611
612**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
613
614**系统接口:** 该接口为系统接口。
615
616**参数:**
617
618| 参数名     | 类型   | 必填 | 说明 |
619| ---------- | ------ | ---- | ---- |
620| uri | string | 是   | 待下载文件uri |
621| callback | AsyncCallback<void> | 是   | 异步启动云文件下载的回调 |
622
623**错误码:**
624
625以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
626
627| 错误码ID                     | 错误信息        |
628| ---------------------------- | ---------- |
629| 201 | Permission verification failed. |
630| 202 | The caller is not a system application. |
631| 401 | The input parameter is invalid. |
632| 13900002 | No such file or directory. |
633| 13900025 | No space left on device. |
634
635**示例:**
636
637  ```ts
638  import { BusinessError } from '@ohos.base';
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.info("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<void>
654
655异步方法停止云文件下载, 以Promise形式返回结果。
656
657> **说明:**
658>
659> 调用stop接口, 当前文件下载流程会终止, 缓存文件会被删除,再次调用start接口会重新开始下载
660
661**需要权限**:ohos.permission.CLOUDFILE_SYNC
662
663**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
664
665**系统接口:** 该接口为系统接口。
666
667**参数:**
668
669| 参数名     | 类型   | 必填 | 说明 |
670| ---------- | ------ | ---- | ---- |
671| uri | string | 是   | 待下载文件uri |
672
673**返回值:**
674
675| 类型                  | 说明             |
676| --------------------- | ---------------- |
677| Promise<void> | 使用Promise形式返回停止云文件下载的结果 |
678
679**错误码:**
680
681以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
682
683| 错误码ID                     | 错误信息        |
684| ---------------------------- | ---------- |
685| 201 | Permission verification failed. |
686| 202 | The caller is not a system application. |
687| 401 | The input parameter is invalid. |
688
689**示例:**
690
691  ```ts
692  import { BusinessError } from '@ohos.base';
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.info("stop download failed with error message: " + err.message + ", error code: " + err.code);
700  });
701  ```
702
703### stop
704
705stop(uri: string, callback: AsyncCallback<void>): void
706
707异步方法停止云文件下载, 以callback形式返回结果。
708
709> **说明:**
710>
711> 调用stop接口, 当前文件下载流程会终止, 缓存文件会被删除, 再次调用start接口会重新开始下载
712
713**需要权限**:ohos.permission.CLOUDFILE_SYNC
714
715**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
716
717**系统接口:** 该接口为系统接口。
718
719**参数:**
720
721| 参数名     | 类型   | 必填 | 说明 |
722| ---------- | ------ | ---- | ---- |
723| uri | string | 是   | 待下载文件uri |
724| callback | AsyncCallback<void> | 是   | 异步停止云文件下载的回调 |
725
726**错误码:**
727
728以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
729
730| 错误码ID                     | 错误信息        |
731| ---------------------------- | ---------- |
732| 201 | Permission verification failed. |
733| 202 | The caller is not a system application. |
734| 401 | The input parameter is invalid. |
735
736**示例:**
737
738  ```ts
739  import { BusinessError } from '@ohos.base';
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.info("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
754云盘同步对象,用于支撑文件管理器应用完成云盘文件的端云同步流程。在使用前,需要先创建FileSync实例。
755
756### constructor<sup>11+</sup>
757
758constructor()
759
760端云同步流程的构造函数,用于获取FileSync类的实例。
761
762**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
763
764**系统接口:** 该接口为系统接口。
765
766**错误码:**
767
768以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
769
770| 错误码ID                     | 错误信息        |
771| ---------------------------- | ---------- |
772| 202 | Permission verification failed, application which is not a system application uses system API. |
773| 401 | The input parameter is invalid. |
774
775**示例:**
776
777  ```ts
778  let fileSync = new cloudSync.FileSync()
779  ```
780
781### on<sup>11+</sup>
782
783on(event: 'progress', callback: Callback\<SyncProgress>): void
784
785添加同步过程事件监听。
786
787**需要权限**:ohos.permission.CLOUDFILE_SYNC
788
789**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
790
791**系统接口:** 该接口为系统接口。
792
793**参数:**
794
795| 参数名     | 类型   | 必填 | 说明 |
796| ---------- | ------ | ---- | ---- |
797| event | string | 是   | 订阅的事件类型,取值为'progress'(同步过程事件) |
798| callback | Callback\<[SyncProgress](#syncprogress)> | 是   | 同步过程事件回调。|
799
800**错误码:**
801
802以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
803
804| 错误码ID                     | 错误信息        |
805| ---------------------------- | ---------- |
806| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. |
807| 202 | Permission verification failed, application which is not a system application uses system API. |
808| 401 | The input parameter is invalid. |
809| 13600001  | IPC error. |
810
811**示例:**
812
813  ```ts
814  let fileSync = new cloudSync.FileSync();
815  let callback = (pg: cloudSync.SyncProgress) => {
816    console.info("file sync state:" + pg.state + "error type:" + pg.error);
817  }
818
819  fileSync.on('progress', callback);
820  ```
821
822### off<sup>11+</sup>
823
824off(event: 'progress', callback?: Callback\<SyncProgress>): void
825
826移除同步过程事件监听。
827
828**需要权限**:ohos.permission.CLOUDFILE_SYNC
829
830**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
831
832**系统接口:** 该接口为系统接口。
833
834**参数:**
835
836| 参数名     | 类型   | 必填 | 说明 |
837| ---------- | ------ | ---- | ---- |
838| event | string | 是   | 取消订阅的事件类型,取值为'progress'(同步过程事件)|
839| callback | Callback\<[SyncProgress](#syncprogress)> |  否   | 同步过程事件回调。 |
840
841**错误码:**
842
843以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
844
845| 错误码ID                     | 错误信息        |
846| ---------------------------- | ---------- |
847| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. |
848| 202 | Permission verification failed, application which is not a system application uses system API. |
849| 401 | The input parameter is invalid. |
850| 13600001  | IPC error. |
851
852**示例:**
853
854  ```ts
855  let fileSync = new cloudSync.FileSync();
856
857  let callback = (pg: cloudSync.SyncProgress) => {
858    console.info("file sync state:" + pg.state + "error type:" + pg.error);
859  }
860
861  fileSync.on('progress', callback);
862
863  fileSync.off('progress', callback);
864  ```
865
866### start<sup>11+</sup>
867
868start(): Promise&lt;void&gt;
869
870异步方法启动云盘端云同步, 以Promise形式返回结果。
871
872**需要权限**:ohos.permission.CLOUDFILE_SYNC
873
874**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
875
876**系统接口:** 该接口为系统接口。
877
878**返回值:**
879
880| 类型                  | 说明             |
881| --------------------- | ---------------- |
882| Promise&lt;void&gt; | Promise对象,无返回值。 |
883
884**错误码:**
885
886以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
887
888| 错误码ID                     | 错误信息        |
889| ---------------------------- | ---------- |
890| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. |
891| 202 | Permission verification failed, application which is not a system application uses system API. |
892| 401 | The input parameter is invalid. |
893| 13600001  | IPC error. |
894| 22400001  | Cloud status not ready. |
895| 22400002  | Network unavailable. |
896| 22400003  | Battery level warning. |
897
898**示例:**
899
900  ```ts
901  import { BusinessError } from '@ohos.base';
902  let fileSync = new cloudSync.FileSync();
903
904  let callback = (pg: cloudSync.SyncProgress) => {
905    console.info("file sync state:" + pg.state + "error type:" + pg.error);
906  }
907
908  fileSync.on('progress', callback);
909
910  fileSync.start().then(() => {
911	  console.info("start sync successfully");
912  }).catch((err: BusinessError) => {
913	  console.info("start sync failed with error message: " + err.message + ", error code: " + err.code);
914  });
915  ```
916
917### start<sup>11+</sup>
918
919start(callback: AsyncCallback&lt;void&gt;): void
920
921异步方法启动云盘端云同步, 以callback形式返回结果。
922
923**需要权限**:ohos.permission.CLOUDFILE_SYNC
924
925**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
926
927**系统接口:** 该接口为系统接口。
928
929**参数:**
930
931| 参数名     | 类型   | 必填 | 说明 |
932| ---------- | ------ | ---- | ---- |
933| callback | AsyncCallback&lt;void&gt; | 是   | 异步启动端云同步的回调。 |
934
935**错误码:**
936
937以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
938
939| 错误码ID                     | 错误信息        |
940| ---------------------------- | ---------- |
941| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. |
942| 202 | Permission verification failed, application which is not a system application uses system API. |
943| 401 | The input parameter is invalid. |
944| 13600001  | IPC error. |
945| 22400001  | Cloud status not ready. |
946| 22400002  | Network unavailable. |
947| 22400003  | Battery level warning. |
948
949**示例:**
950
951  ```ts
952  import { BusinessError } from '@ohos.base';
953  let fileSync = new cloudSync.FileSync();
954
955  fileSync.start((err: BusinessError) => {
956    if (err) {
957      console.info("start sync failed with error message: " + err.message + ", error code: " + err.code);
958    } else {
959      console.info("start sync successfully");
960    }
961  });
962  ```
963
964### stop<sup>11+</sup>
965
966stop(): Promise&lt;void&gt;
967
968异步方法停止云盘端云同步, 以Promise形式返回结果。
969
970调用stop接口,同步流程会停止。再次调用[start](#start)接口会继续同步。
971
972**需要权限**:ohos.permission.CLOUDFILE_SYNC
973
974**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
975
976**系统接口:** 该接口为系统接口。
977
978**返回值:**
979
980| 类型                  | 说明             |
981| --------------------- | ---------------- |
982| Promise&lt;void&gt; | 使用Promise形式返回停止端云同步的结果。 |
983
984**错误码:**
985
986以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
987
988| 错误码ID                     | 错误信息        |
989| ---------------------------- | ---------- |
990| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. |
991| 202 | Permission verification failed, application which is not a system application uses system API. |
992| 401 | The input parameter is invalid. |
993| 13600001  | IPC error. |
994
995**示例:**
996
997  ```ts
998  import { BusinessError } from '@ohos.base';
999  let fileSync = new cloudSync.FileSync();
1000
1001  fileSync.stop().then(() => {
1002	  console.info("stop sync successfully");
1003  }).catch((err: BusinessError) => {
1004	  console.info("stop sync failed with error message: " + err.message + ", error code: " + err.code);
1005  });
1006  ```
1007
1008### stop<sup>11+</sup>
1009
1010stop(callback: AsyncCallback&lt;void&gt;): void
1011
1012异步方法停止云盘端云同步, 以callback形式返回结果。
1013
1014调用stop接口,同步流程会停止。再次调用[start](#start)接口会继续同步。
1015
1016**需要权限**:ohos.permission.CLOUDFILE_SYNC
1017
1018**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
1019
1020**系统接口:** 该接口为系统接口。
1021
1022**参数:**
1023
1024| 参数名     | 类型   | 必填 | 说明 |
1025| ---------- | ------ | ---- | ---- |
1026| callback | AsyncCallback&lt;void&gt; | 是   | 异步停止端云同步的回调。 |
1027
1028**错误码:**
1029
1030以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
1031
1032| 错误码ID                     | 错误信息        |
1033| ---------------------------- | ---------- |
1034| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. |
1035| 202 | Permission verification failed, application which is not a system application uses system API. |
1036| 401 | The input parameter is invalid. |
1037| 13600001  | IPC error. |
1038
1039**示例:**
1040
1041  ```ts
1042  import { BusinessError } from '@ohos.base';
1043  let fileSync = new cloudSync.FileSync();
1044
1045  fileSync.stop((err: BusinessError) => {
1046    if (err) {
1047      console.info("stop sync failed with error message: " + err.message + ", error code: " + err.code);
1048    } else {
1049      console.info("stop sync successfully");
1050    }
1051  });
1052  ```
1053
1054### getLastSyncTime<sup>11+</sup>
1055
1056getLastSyncTime(): Promise&lt;number&gt;
1057
1058异步方法获取上次同步时间, 以promise形式返回结果。
1059
1060**需要权限**:ohos.permission.CLOUDFILE_SYNC
1061
1062**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
1063
1064**系统接口:** 该接口为系统接口。
1065
1066**返回值:**
1067
1068| 类型                  | 说明             |
1069| --------------------- | ---------------- |
1070| Promise&lt;number&gt; | 使用Promise形式返回上次同步时间。 |
1071
1072**错误码:**
1073
1074以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
1075
1076| 错误码ID                     | 错误信息        |
1077| ---------------------------- | ---------- |
1078| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. |
1079| 202 | Permission verification failed, application which is not a system application uses system API. |
1080| 401 | The input parameter is invalid. |
1081| 13600001  | IPC error. |
1082
1083**示例:**
1084
1085  ```ts
1086  import { BusinessError } from '@ohos.base';
1087  let fileSync = new cloudSync.FileSync();
1088
1089  fileSync.getLastSyncTime().then((timeStamp: number) => {
1090    let date = new Date(timeStamp);
1091    console.info("get last sync time successfully:"+ date);
1092  }).catch((err: BusinessError) => {
1093	  console.info("get last sync time failed with error message: " + err.message + ", error code: " + err.code);
1094  });
1095
1096  ```
1097
1098### getLastSyncTime<sup>11+</sup>
1099
1100getLastSyncTime(callback: AsyncCallback&lt;number&gt;): void;
1101
1102异步方法获取上次同步时间, 以callback形式返回结果。
1103
1104**需要权限**:ohos.permission.CLOUDFILE_SYNC
1105
1106**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
1107
1108**系统接口:** 该接口为系统接口。
1109
1110**参数:**
1111
1112| 参数名     | 类型   | 必填 | 说明 |
1113| ---------- | ------ | ---- | ---- |
1114| callback | AsyncCallback&lt;number&gt; | 是   | 异步获取上次同步时间的回调。|
1115
1116**错误码:**
1117
1118以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
1119
1120| 错误码ID                     | 错误信息        |
1121| ---------------------------- | ---------- |
1122| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. |
1123| 202 | Permission verification failed, application which is not a system application uses system API. |
1124| 401 | The input parameter is invalid. |
1125| 13600001  | IPC error. |
1126
1127**示例:**
1128
1129  ```ts
1130  import { BusinessError } from '@ohos.base';
1131  let fileSync = new cloudSync.FileSync();
1132
1133  fileSync.getLastSyncTime((err: BusinessError, timeStamp: number) => {
1134    if (err) {
1135      console.info("get last sync time with error message: " + err.message + ", error code: " + err.code);
1136    } else {
1137      let date = new Date(timeStamp);
1138      console.info("get last sync time successfully:"+ date);
1139    }
1140  });
1141  ```
1142
1143## CloudFileCache<sup>11+</sup>
1144
1145云盘文件缓存对象,用来支撑文件管理应用原文件下载流程。
1146
1147**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
1148
1149### cleanCache<sup>11+</sup>
1150
1151cleanCache(uri: string): void;
1152
1153同步方法删除文件缓存
1154
1155**需要权限**:ohos.permission.CLOUDFILE_SYNC
1156
1157**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
1158
1159**系统接口:** 该接口为系统接口。
1160
1161**参数:**
1162
1163| 参数名     | 类型   | 必填 | 说明 |
1164| ---------- | ------ | ---- | ---- |
1165| uri | string | 是   | 待删除缓存文件的uri。|
1166
1167**错误码:**
1168
1169以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
1170
1171| 错误码ID                     | 错误信息        |
1172| ---------------------------- | ---------- |
1173| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. |
1174| 202 | Permission verification failed, application which is not a system application uses system API. |
1175| 401 | The input parameter is invalid. |
1176| 13600001  | IPC error. |
1177| 13900002  | No such file or directory. |
1178| 14000002  | Invalid uri. |
1179
1180**示例:**
1181
1182  ```ts
1183  import { BusinessError } from '@ohos.base';
1184  import fileUri from '@ohos.file.fileuri';
1185  let fileCache = new cloudSync.CloudFileCache();
1186  let path = "/data/storage/el2/cloud/1.txt";
1187  let uri = fileUri.getUriFromPath(path);
1188
1189  try {
1190    fileCache.cleanCache(uri);
1191  } catch (err) {
1192    let error:BusinessError = err as BusinessError;
1193    console.info("clean cache failed with error message: " + err.message + ", error code: " + err.code);
1194  }
1195
1196  ```
1197
1198## cloudSync.getFileSyncState<sup>11+</sup>
1199
1200getFileSyncState(uri: Array&lt;string&gt;): Promise&lt;Array&lt;FileSyncState&gt;&gt;
1201
1202异步方法获取文件同步状态, 以promise形式返回结果。
1203
1204**需要权限**:ohos.permission.CLOUDFILE_SYNC
1205
1206**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
1207
1208**系统接口:** 该接口为系统接口。
1209
1210**参数:**
1211
1212| 参数名     | 类型   | 必填 | 说明 |
1213| ---------- | ------ | ---- | ---- |
1214| uri | Array&lt;string&gt; | 是   | 待获取同步状态的uri。 |
1215
1216**返回值:**
1217
1218| 类型                  | 说明             |
1219| --------------------- | ---------------- |
1220| Promise&lt;Array&lt;FileSyncState&gt;&gt; | 使用Promise形式返回文件同步状态的结果。 |
1221
1222**错误码:**
1223
1224以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
1225
1226| 错误码ID                     | 错误信息        |
1227| ---------------------------- | ---------- |
1228| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. |
1229| 202 | Permission verification failed, application which is not a system application uses system API. |
1230| 401 | The input parameter is invalid. |
1231| 13600001  | IPC error. |
1232| 13900002  | No such file or directory. |
1233| 14000002  | Invalid uri. |
1234
1235**示例:**
1236
1237  ```ts
1238  import { BusinessError } from '@ohos.base';
1239
1240  let uris: Array<string> = ["file://uri"];
1241  cloudSync.getFileSyncState(uris).then(function(syncStates: Array<cloudSync.FileSyncState>) {
1242    for(let i = 0, len = syncStates.length; i < len; i++){
1243        console.info("get file sync state successfully" + syncStates[i]);
1244    }
1245  }).catch((err: BusinessError) => {
1246	  console.info("get file sync state failed with error message: " + err.message + ", error code: " + err.code);
1247  });
1248
1249  ```
1250
1251## cloudSync.getFileSyncState<sup>11+</sup>
1252
1253getFileSyncState(uri: Array&lt;string&gt;, callback: AsyncCallback&lt;Array&lt;FileSyncState&gt;&gt;): void
1254
1255异步方法获取文件同步状态, 以callback形式返回结果。
1256
1257**需要权限**:ohos.permission.CLOUDFILE_SYNC
1258
1259**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
1260
1261**系统接口:** 该接口为系统接口。
1262
1263**参数:**
1264
1265| 参数名     | 类型   | 必填 | 说明 |
1266| ---------- | ------ | ---- | ---- |
1267| uri | Array&lt;string&gt; | 是   | 待获取同步状态的uri。 |
1268| callback | AsyncCallback&lt;Array&lt;FileSyncState&gt;&gt; | 是   | 异步获取文件状态的回调。|
1269
1270**错误码:**
1271
1272以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。
1273
1274| 错误码ID                     | 错误信息        |
1275| ---------------------------- | ---------- |
1276| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. |
1277| 202 | Permission verification failed, application which is not a system application uses system API. |
1278| 401 | The input parameter is invalid. |
1279| 13600001  | IPC error. |
1280| 13900002  | No such file or directory. |
1281| 14000002  | Invalid uri. |
1282
1283**示例:**
1284
1285  ```ts
1286  import { BusinessError } from '@ohos.base';
1287
1288  let uris: Array<string> = ["file://uri"];
1289  cloudSync.getFileSyncState(uris, (err: BusinessError, syncStates: Array<cloudSync.FileSyncState>) => {
1290    if (err) {
1291      console.info("get file sync state with error message: " + err.message + ", error code: " + err.code);
1292    } else {
1293      for(let i = 0, len = syncStates.length; i < len; i++){
1294        console.info("get file sync state successfully" + syncStates[i]);
1295    }
1296    }
1297  });
1298  ```
1299
1300## FileSyncState<sup>11+</sup>
1301
1302端云文件同步状态,为枚举类型。
1303
1304**系统能力**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
1305
1306**系统接口:** 该接口为系统接口。
1307
1308| 名称 |  值|  说明 |
1309| ----- |  ---- |  ---- |
1310| UPLOADING |  0 | 上行同步中 |
1311| DOWNLOADING |  1 | 下行同步中 |
1312| COMPLETED |  2 | 同步成功 |
1313| STOPPED |  3 | 同步已停止 |
1314