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<sup>12+</sup> 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<sup>12+</sup> 38 39端云同步失败类型,为枚举类型。 40 41- 当前阶段,同步过程中,当开启无限量使用移动数据网络,移动数据网络和WIFI均不可用时,才会返回NETWORK_UNAVAILABLE;开启无限量使用移动数据网络,若有一种类型网络可用,则能正常同步。 42- 同步过程中,非充电场景下,电量低于10%,完成当前批上行同步后停止同步,返回低电量; 43- 触发同步时,非充电场景下,若电量低于10%,则不允许同步,start接口返回对应错误。 44- 上行时,若云端空间不足,则文件上行失败,云端无该文件记录 45 46**系统能力**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 47 48**系统接口**:该接口为系统接口。 49 50| 名称 | 值| 说明 | 51| ----- | ---- | ---- | 52| NO_ERROR | 0 | 没有错误。 | 53| NETWORK_UNAVAILABLE | 1 | 所有网络不可用。 | 54| WIFI_UNAVAILABLE | 2 | WIFI不可用。 | 55| BATTERY_LEVEL_LOW | 3 | 低电量(低于10%)。 | 56| BATTERY_LEVEL_WARNING | 4 | 告警电量(低于15%)。 | 57| CLOUD_STORAGE_FULL | 5 | 云端空间不足。 | 58| LOCAL_STORAGE_FULL | 6 | 本地空间不足。 | 59| DEVICE_TEMPERATURE_TOO_HIGH | 7 | 设备温度过高。 | 60 61## SyncProgress<sup>12+</sup> 62 63端云同步过程。 64 65**系统能力**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 66 67**系统接口**:该接口为系统接口。 68 69| 名称 | 类型 | 必填 | 说明 | 70| ---------- | ------ | ---- | ---- | 71| state | [SyncState](#syncstate12) | 是 | 枚举值,端云同步状态。| 72| error | [ErrorType](#errortype12) | 是 | 枚举值,同步失败错误类型。| 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](#syncprogress12), 返回值为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. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 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](#syncprogress12), 返回值为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. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 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. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 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. Possible causes:Incorrect parameter types. | 246| 22400001 | Cloud status not ready. | 247| 22400002 | Network unavailable. | 248| 22400003 | Low battery level. | 249 250**示例:** 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<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. 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**示例:** 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<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. Possible causes:Incorrect parameter types. | 344 345**示例:** 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<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. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 389 390**示例:** 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 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. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 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. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 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. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 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 '@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**错误码:** 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. 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<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. 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**示例:** 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<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. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 688 689**示例:** 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<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. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 735 736**示例:** 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>12+</sup> 753 754云盘同步对象,用于支撑文件管理器应用完成云盘文件的端云同步流程。在使用前,需要先创建FileSync实例。 755 756### constructor<sup>12+</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. Possible causes:Incorrect parameter types. | 774 775**示例:** 776 777 ```ts 778 let fileSync = new cloudSync.FileSync() 779 ``` 780 781### constructor<sup>12+</sup> 782 783constructor(bundleName: string) 784 785端云同步流程的构造函数,用于获取FileSync类的实例。 786 787**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 788 789**系统接口**:该接口为系统接口。 790 791**参数:** 792 793| 参数名 | 类型 | 必填 | 说明 | 794| ---------- | ------ | ---- | ---- | 795| bundleName | string | 是 | 应用包名。| 796 797**错误码:** 798 799以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 800 801| 错误码ID | 错误信息 | 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**示例:** 807 808 ```ts 809 let fileSync = new cloudSync.FileSync("com.ohos.demo") 810 ``` 811 812### on<sup>12+</sup> 813 814on(event: 'progress', callback: Callback\<SyncProgress>): void 815 816添加同步过程事件监听。 817 818**需要权限**:ohos.permission.CLOUDFILE_SYNC 819 820**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 821 822**系统接口**:该接口为系统接口。 823 824**参数:** 825 826| 参数名 | 类型 | 必填 | 说明 | 827| ---------- | ------ | ---- | ---- | 828| event | string | 是 | 订阅的事件类型,取值为'progress'(同步过程事件)。 | 829| callback | Callback\<[SyncProgress](#syncprogress12)> | 是 | 同步过程事件回调。| 830 831**错误码:** 832 833以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 834 835| 错误码ID | 错误信息 | 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**示例:** 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>12+</sup> 854 855off(event: 'progress', callback?: Callback\<SyncProgress>): void 856 857移除同步过程事件监听。 858 859**需要权限**:ohos.permission.CLOUDFILE_SYNC 860 861**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 862 863**系统接口**:该接口为系统接口。 864 865**参数:** 866 867| 参数名 | 类型 | 必填 | 说明 | 868| ---------- | ------ | ---- | ---- | 869| event | string | 是 | 取消订阅的事件类型,取值为'progress'(同步过程事件)。| 870| callback | Callback\<[SyncProgress](#syncprogress12)> | 否 | 同步过程事件回调。 | 871 872**错误码:** 873 874以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 875 876| 错误码ID | 错误信息 | 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**示例:** 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>12+</sup> 898 899start(): Promise<void> 900 901异步方法启动云盘端云同步, 以Promise形式返回结果。 902 903**需要权限**:ohos.permission.CLOUDFILE_SYNC 904 905**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 906 907**系统接口**:该接口为系统接口。 908 909**返回值:** 910 911| 类型 | 说明 | 912| --------------------- | ---------------- | 913| Promise<void> | Promise对象,无返回值。 | 914 915**错误码:** 916 917以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 918 919| 错误码ID | 错误信息 | 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**示例:** 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>12+</sup> 949 950start(callback: AsyncCallback<void>): void 951 952异步方法启动云盘端云同步, 以callback形式返回结果。 953 954**需要权限**:ohos.permission.CLOUDFILE_SYNC 955 956**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 957 958**系统接口**:该接口为系统接口。 959 960**参数:** 961 962| 参数名 | 类型 | 必填 | 说明 | 963| ---------- | ------ | ---- | ---- | 964| callback | AsyncCallback<void> | 是 | 异步启动端云同步的回调。 | 965 966**错误码:** 967 968以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 969 970| 错误码ID | 错误信息 | 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**示例:** 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>12+</sup> 996 997stop(): Promise<void> 998 999异步方法停止云盘端云同步, 以Promise形式返回结果。 1000 1001调用stop接口,同步流程会停止。再次调用[start](#start)接口会继续同步。 1002 1003**需要权限**:ohos.permission.CLOUDFILE_SYNC 1004 1005**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1006 1007**系统接口**:该接口为系统接口。 1008 1009**返回值:** 1010 1011| 类型 | 说明 | 1012| --------------------- | ---------------- | 1013| Promise<void> | 使用Promise形式返回停止端云同步的结果。 | 1014 1015**错误码:** 1016 1017以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 1018 1019| 错误码ID | 错误信息 | 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**示例:** 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>12+</sup> 1040 1041stop(callback: AsyncCallback<void>): void 1042 1043异步方法停止云盘端云同步, 以callback形式返回结果。 1044 1045调用stop接口,同步流程会停止。再次调用[start](#start)接口会继续同步。 1046 1047**需要权限**:ohos.permission.CLOUDFILE_SYNC 1048 1049**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1050 1051**系统接口**:该接口为系统接口。 1052 1053**参数:** 1054 1055| 参数名 | 类型 | 必填 | 说明 | 1056| ---------- | ------ | ---- | ---- | 1057| callback | AsyncCallback<void> | 是 | 异步停止端云同步的回调。 | 1058 1059**错误码:** 1060 1061以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 1062 1063| 错误码ID | 错误信息 | 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**示例:** 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>12+</sup> 1086 1087getLastSyncTime(): Promise<number> 1088 1089异步方法获取上次同步时间, 以promise形式返回结果。 1090 1091**需要权限**:ohos.permission.CLOUDFILE_SYNC 1092 1093**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1094 1095**系统接口**:该接口为系统接口。 1096 1097**返回值:** 1098 1099| 类型 | 说明 | 1100| --------------------- | ---------------- | 1101| Promise<number> | 使用Promise形式返回上次同步时间。 | 1102 1103**错误码:** 1104 1105以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 1106 1107| 错误码ID | 错误信息 | 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**示例:** 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>12+</sup> 1130 1131getLastSyncTime(callback: AsyncCallback<number>): void 1132 1133异步方法获取上次同步时间, 以callback形式返回结果。 1134 1135**需要权限**:ohos.permission.CLOUDFILE_SYNC 1136 1137**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1138 1139**系统接口**:该接口为系统接口。 1140 1141**参数:** 1142 1143| 参数名 | 类型 | 必填 | 说明 | 1144| ---------- | ------ | ---- | ---- | 1145| callback | AsyncCallback<number> | 是 | 异步获取上次同步时间的回调。| 1146 1147**错误码:** 1148 1149以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 1150 1151| 错误码ID | 错误信息 | 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**示例:** 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 1176云盘文件缓存对象,用来支撑文件管理应用原文件下载流程。 1177 1178**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1179 1180### cleanCache<sup>11+</sup> 1181 1182cleanCache(uri: string): void 1183 1184同步方法删除文件缓存。 1185 1186**需要权限**:ohos.permission.CLOUDFILE_SYNC 1187 1188**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1189 1190**系统接口**:该接口为系统接口。 1191 1192**参数:** 1193 1194| 参数名 | 类型 | 必填 | 说明 | 1195| ---------- | ------ | ---- | ---- | 1196| uri | string | 是 | 待删除缓存文件的uri。| 1197 1198**错误码:** 1199 1200以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 1201 1202| 错误码ID | 错误信息 | 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**示例:** 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<string>): Promise<Array<FileSyncState>> 1232 1233异步方法获取文件同步状态, 以promise形式返回结果。 1234 1235**需要权限**:ohos.permission.CLOUDFILE_SYNC 1236 1237**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1238 1239**系统接口**:该接口为系统接口。 1240 1241**参数:** 1242 1243| 参数名 | 类型 | 必填 | 说明 | 1244| ---------- | ------ | ---- | ---- | 1245| uri | Array<string> | 是 | 待获取同步状态的uri。 | 1246 1247**返回值:** 1248 1249| 类型 | 说明 | 1250| --------------------- | ---------------- | 1251| Promise<Array<FileSyncState>> | 使用Promise形式返回文件同步状态的结果。 | 1252 1253**错误码:** 1254 1255以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 1256 1257| 错误码ID | 错误信息 | 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**示例:** 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<string>, callback: AsyncCallback<Array<FileSyncState>>): void 1285 1286异步方法获取文件同步状态, 以callback形式返回结果。 1287 1288**需要权限**:ohos.permission.CLOUDFILE_SYNC 1289 1290**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1291 1292**系统接口**:该接口为系统接口。 1293 1294**参数:** 1295 1296| 参数名 | 类型 | 必填 | 说明 | 1297| ---------- | ------ | ---- | ---- | 1298| uri | Array<string> | 是 | 待获取同步状态的uri。 | 1299| callback | AsyncCallback<Array<FileSyncState>> | 是 | 异步获取文件状态的回调。| 1300 1301**错误码:** 1302 1303以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 1304 1305| 错误码ID | 错误信息 | 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**示例:** 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 1335获取文件同步状态。 1336 1337**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1338 1339**系统接口**:该接口为系统接口。 1340 1341**参数:** 1342 1343| 参数名 | 类型 | 必填 | 说明 | 1344| ---------- | ------ | ---- | ---- | 1345| uri | string | 是 | 待下载文件uri。 | 1346 1347**返回值:** 1348 1349| 类型 | 说明 | 1350| --------------------- | ---------------- | 1351| [FileSyncState](#filesyncstate11) | 返回给定文件的同步状态。 | 1352 1353**错误码:** 1354 1355以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 1356 1357| 错误码ID | 错误信息 | 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**示例:** 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<ChangeData>): void 1387 1388订阅监听指定文件的变化通知。 1389 1390**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1391 1392**系统接口**:该接口为系统接口。 1393 1394**参数:** 1395 1396| 参数名 | 类型 | 必填 | 说明 | 1397| ---------- | ------ | ---- | ---- | 1398| uri | string | 是 | 待下载文件uri。 | 1399| recursion | boolean | 是 | true为监听该uri以及子文件和子目录,false为仅监听该uri文件。| 1400| callback | Callback<[ChangeData](#changedata12)> | 是 | 返回更改的数据。 | 1401 1402**错误码:** 1403 1404以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 1405 1406| 错误码ID | 错误信息 | 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**示例:** 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 // 取消注册监听 1430 cloudSync.unRegisterChange(uri); 1431 ``` 1432 1433## cloudSync.unregisterChange<sup>12+</sup> 1434 1435unregisterChange(uri: string): void 1436 1437取消订阅监听指定文件的变化通知。 1438 1439**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1440 1441**系统接口**:该接口为系统接口。 1442 1443**参数:** 1444 1445| 参数名 | 类型 | 必填 | 说明 | 1446| ---------- | ------ | ---- | ---- | 1447| uri | string | 是 | 待下载文件uri。 | 1448 1449**错误码:** 1450 1451以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 1452 1453| 错误码ID | 错误信息 | 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**示例:** 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 // 取消注册监听 1477 cloudSync.unRegisterChange(uri); 1478 ``` 1479 1480## NotifyType<sup>12+</sup> 1481 1482数据变更通知类型。 1483 1484**系统能力**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1485 1486**系统接口**:该接口为系统接口。 1487 1488| 名称 | 值| 说明 | 1489| ----- | ---- | ---- | 1490| NOTIFY_ADDED | 0 | 文件已新建。 | 1491| NOTIFY_MODIFIED | 1 | 文件已修改。 | 1492| NOTIFY_DELETED | 2 | 文件已被删除。 | 1493| NOTIFY_RENAMED | 3 | 文件被重命名或者移动。 | 1494 1495## ChangeData<sup>12+</sup> 1496 1497定义变更数据。 1498 1499**系统能力**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1500 1501**系统接口**:该接口为系统接口。 1502 1503| 名称 | 类型 | 必填 | 说明 | 1504| ---------- | ------ | ---- | ---- | 1505| type | [NotifyType](#notifytype12) | 是 | 更改的通知类型。| 1506| isDirectory | Array<boolean> | 是 | 指示更改的uri是否为目录。| 1507| uris | Array<string> | 是 | 更改的uris。| 1508 1509## FileSyncState<sup>11+</sup> 1510 1511端云文件同步状态,为枚举类型。 1512 1513**系统能力**: SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 1514 1515**系统接口**:该接口为系统接口。 1516 1517| 名称 | 值| 说明 | 1518| ----- | ---- | ---- | 1519| UPLOADING | 0 | 上行同步中。 | 1520| DOWNLOADING | 1 | 下行同步中。 | 1521| COMPLETED | 2 | 同步成功。 | 1522| STOPPED | 3 | 同步已停止。 | 1523| TO_BE_UPLOADED<sup>12+</sup> | 4 | 正在等待上行。 | 1524| UPLOAD_SUCCESS<sup>12+</sup> | 5 | 文件已成功上行。 | 1525| UPLOAD_FAILURE<sup>12+</sup> | 6 | 文件上行失败。 |