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