1# @ohos.file.cloudSync (端云同步能力) 2 3该模块向应用提供端云同步能力,包括启动/停止端云同步以及启动/停止原图下载功能。 4 5> **说明:** 6> 7> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8 9## 导入模块 10 11```ts 12import { cloudSync } from '@kit.CoreFileKit'; 13``` 14## SyncState<sup>12+</sup> 15 16端云同步状态,为枚举类型。 17 18> **说明:** 19> 20> 以下同步状态发生变更时,如果应用注册了同步过程事件监听,则通过回调通知应用。 21 22**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 23 24| 名称 | 值| 说明 | 25| ----- | ---- | ---- | 26| UPLOADING | 0 | 上行同步中。 | 27| UPLOAD_FAILED | 1 | 上行同步失败。 | 28| DOWNLOADING | 2 | 下行同步中。 | 29| DOWNLOAD_FAILED | 3 | 下行同步失败。 | 30| COMPLETED | 4 | 同步成功。 | 31| STOPPED | 5 | 同步已停止。 | 32 33## ErrorType<sup>12+</sup> 34 35端云同步失败类型,为枚举类型。 36 37- 当前阶段,同步过程中,当开启无限量使用移动数据网络,移动数据网络和WIFI均不可用时,才会返回NETWORK_UNAVAILABLE;开启无限量使用移动数据网络,若有一种类型网络可用,则能正常同步。 38- 同步过程中,非充电场景下,电量低于10%,完成当前批上行同步后停止同步,返回低电量; 39- 触发同步时,非充电场景下,若电量低于10%,则不允许同步,start接口返回对应错误。 40- 上行时,若云端空间不足,则文件上行失败,云端无该文件记录。 41 42**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 43 44| 名称 | 值| 说明 | 45| ----- | ---- | ---- | 46| NO_ERROR | 0 | 没有错误。 | 47| NETWORK_UNAVAILABLE | 1 | 所有网络不可用。 | 48| WIFI_UNAVAILABLE | 2 | WIFI不可用。 | 49| BATTERY_LEVEL_LOW | 3 | 低电量(低于10%)。 | 50| BATTERY_LEVEL_WARNING | 4 | 告警电量(低于15%)。 | 51| CLOUD_STORAGE_FULL | 5 | 云端空间不足。 | 52| LOCAL_STORAGE_FULL | 6 | 本地空间不足。 | 53| DEVICE_TEMPERATURE_TOO_HIGH | 7 | 设备温度过高。 | 54 55## SyncProgress<sup>12+</sup> 56 57端云同步过程。 58 59### 属性 60 61**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 62 63| 名称 | 类型 | 必填 | 说明 | 64| ---------- | ------ | ---- | ---- | 65| state | [SyncState](#syncstate12) | 是 | 枚举值,端云同步状态。| 66| error | [ErrorType](#errortype12) | 是 | 枚举值,同步失败错误类型。| 67 68## State<sup>11+</sup> 69 70云文件下载状态,为枚举类型。 71 72**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 73 74| 名称 | 值| 说明 | 75| ----- | ---- | ---- | 76| RUNNING | 0 | 云文件正在下载中。 | 77| COMPLETED | 1 | 云文件下载完成。 | 78| FAILED | 2 | 云文件下载失败。 | 79| STOPPED | 3 | 云文件下载已停止。 | 80 81## DownloadProgress<sup>11+</sup> 82 83云文件下载过程。 84 85### 属性 86 87**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 88 89| 名称 | 类型 | 必填 | 说明 | 90| ---------- | ------ | ---- | ---- | 91| state | [State](#state11) | 是 | 枚举值,云文件下载状态。| 92| processed | number | 是 | 已下载数据大小,取值范围[0,9223372036854775807](单位:Byte)。| 93| size | number | 是 | 当前云文件大小,取值范围[0,9223372036854775807](单位:Byte)。| 94| uri | string | 是 | 当前云文件uri。| 95| error | [DownloadErrorType](#downloaderrortype11) | 是 | 下载的错误类型。| 96 97## FileSync<sup>12+</sup> 98 99云盘同步对象,用于支撑文件管理器应用完成云盘文件的端云同步流程。在使用前,需要先创建FileSync实例。 100 101**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 102 103### constructor<sup>12+</sup> 104 105constructor() 106 107端云同步流程的构造函数,用于获取FileSync类的实例。 108 109**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 110 111**错误码:** 112 113以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 114 115| 错误码ID | 错误信息 | 116| ---------------------------- | ---------- | 117| 202 | Permission verification failed, application which is not a system application uses system API. | 118| 401 | The input parameter is invalid. Possible causes:Incorrect parameter types. | 119 120**示例:** 121 122 ```ts 123 let fileSync = new cloudSync.FileSync() 124 ``` 125 126### on<sup>12+</sup> 127 128on(event: 'progress', callback: Callback\<SyncProgress>): void 129 130添加同步过程事件监听。 131 132**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 133 134**参数:** 135 136| 参数名 | 类型 | 必填 | 说明 | 137| ---------- | ------ | ---- | ---- | 138| event | string | 是 | 订阅的事件类型,取值为'progress'(同步过程事件)。 | 139| callback | Callback\<[SyncProgress](#syncprogress12)> | 是 | 同步过程事件回调。| 140 141**错误码:** 142 143以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 144 145| 错误码ID | 错误信息 | 146| ---------------------------- | ---------- | 147| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 148| 202 | Permission verification failed, application which is not a system application uses system API. | 149| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 150| 13600001 | IPC error. | 151 152**示例:** 153 154 ```ts 155 let fileSync = new cloudSync.FileSync(); 156 let callback = (pg: cloudSync.SyncProgress) => { 157 console.info("file sync state:" + pg.state + "error type:" + pg.error); 158 } 159 160 fileSync.on('progress', callback); 161 ``` 162 163### off<sup>12+</sup> 164 165off(event: 'progress', callback?: Callback\<SyncProgress>): void 166 167移除同步过程事件监听。 168 169**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 170 171**参数:** 172 173| 参数名 | 类型 | 必填 | 说明 | 174| ---------- | ------ | ---- | ---- | 175| event | string | 是 | 取消订阅的事件类型,取值为'progress'(同步过程事件)。| 176| callback | Callback\<[SyncProgress](#syncprogress12)> | 否 | 同步过程事件回调,默认值为null。 | 177 178**错误码:** 179 180以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 181 182| 错误码ID | 错误信息 | 183| ---------------------------- | ---------- | 184| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 185| 202 | Permission verification failed, application which is not a system application uses system API. | 186| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 187| 13600001 | IPC error. | 188 189**示例:** 190 191 ```ts 192 let fileSync = new cloudSync.FileSync(); 193 194 let callback = (pg: cloudSync.SyncProgress) => { 195 console.info("file sync state:" + pg.state + "error type:" + pg.error); 196 } 197 198 fileSync.on('progress', callback); 199 200 fileSync.off('progress', callback); 201 ``` 202 203### start<sup>12+</sup> 204 205start(): Promise<void> 206 207异步方法启动云盘端云同步,以Promise形式返回结果。 208 209**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 210 211**返回值:** 212 213| 类型 | 说明 | 214| --------------------- | ---------------- | 215| Promise<void> | Promise对象,无返回值。 | 216 217**错误码:** 218 219以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 220 221| 错误码ID | 错误信息 | 222| ---------------------------- | ---------- | 223| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 224| 202 | Permission verification failed, application which is not a system application uses system API. | 225| 401 | The input parameter is invalid. Possible causes:Incorrect parameter types. | 226| 13600001 | IPC error. | 227| 22400001 | Cloud status not ready. | 228| 22400002 | Network unavailable. | 229| 22400003 | Low battery level. | 230 231**示例:** 232 233 ```ts 234 import { BusinessError } from '@kit.BasicServicesKit'; 235 let fileSync = new cloudSync.FileSync(); 236 237 let callback = (pg: cloudSync.SyncProgress) => { 238 console.info("file sync state:" + pg.state + "error type:" + pg.error); 239 } 240 241 fileSync.on('progress', callback); 242 243 fileSync.start().then(() => { 244 console.info("start sync successfully"); 245 }).catch((err: BusinessError) => { 246 console.error("start sync failed with error message: " + err.message + ", error code: " + err.code); 247 }); 248 ``` 249 250### start<sup>12+</sup> 251 252start(callback: AsyncCallback<void>): void 253 254异步方法启动云盘端云同步,以callback形式返回结果。 255 256**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 257 258**参数:** 259 260| 参数名 | 类型 | 必填 | 说明 | 261| ---------- | ------ | ---- | ---- | 262| callback | AsyncCallback<void> | 是 | 异步启动端云同步的回调。 | 263 264**错误码:** 265 266以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 267 268| 错误码ID | 错误信息 | 269| ---------------------------- | ---------- | 270| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 271| 202 | Permission verification failed, application which is not a system application uses system API. | 272| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 273| 13600001 | IPC error. | 274| 22400001 | Cloud status not ready. | 275| 22400002 | Network unavailable. | 276| 22400003 | Low battery level. | 277 278**示例:** 279 280 ```ts 281 import { BusinessError } from '@kit.BasicServicesKit'; 282 let fileSync = new cloudSync.FileSync(); 283 284 fileSync.start((err: BusinessError) => { 285 if (err) { 286 console.error("start sync failed with error message: " + err.message + ", error code: " + err.code); 287 } else { 288 console.info("start sync successfully"); 289 } 290 }); 291 ``` 292 293### stop<sup>12+</sup> 294 295stop(): Promise<void> 296 297异步方法停止云盘端云同步,以Promise形式返回结果。 298 299调用stop接口,同步流程会停止。再次调用[start](#start12)接口会继续同步。 300 301**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 302 303**返回值:** 304 305| 类型 | 说明 | 306| --------------------- | ---------------- | 307| Promise<void> | 使用Promise形式返回停止端云同步的结果。 | 308 309**错误码:** 310 311以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 312 313| 错误码ID | 错误信息 | 314| ---------------------------- | ---------- | 315| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 316| 202 | Permission verification failed, application which is not a system application uses system API. | 317| 401 | The input parameter is invalid. Possible causes:Incorrect parameter types. | 318| 13600001 | IPC error. | 319 320**示例:** 321 322 ```ts 323 import { BusinessError } from '@kit.BasicServicesKit'; 324 let fileSync = new cloudSync.FileSync(); 325 326 fileSync.stop().then(() => { 327 console.info("stop sync successfully"); 328 }).catch((err: BusinessError) => { 329 console.error("stop sync failed with error message: " + err.message + ", error code: " + err.code); 330 }); 331 ``` 332 333### stop<sup>12+</sup> 334 335stop(callback: AsyncCallback<void>): void 336 337异步方法停止云盘端云同步,以callback形式返回结果。 338 339调用stop接口,同步流程会停止。再次调用[start](#start12)接口会继续同步。 340 341**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 342 343**参数:** 344 345| 参数名 | 类型 | 必填 | 说明 | 346| ---------- | ------ | ---- | ---- | 347| callback | AsyncCallback<void> | 是 | 异步停止端云同步的回调。 | 348 349**错误码:** 350 351以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 352 353| 错误码ID | 错误信息 | 354| ---------------------------- | ---------- | 355| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 356| 202 | Permission verification failed, application which is not a system application uses system API. | 357| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 358| 13600001 | IPC error. | 359 360**示例:** 361 362 ```ts 363 import { BusinessError } from '@kit.BasicServicesKit'; 364 let fileSync = new cloudSync.FileSync(); 365 366 fileSync.stop((err: BusinessError) => { 367 if (err) { 368 console.error("stop sync failed with error message: " + err.message + ", error code: " + err.code); 369 } else { 370 console.info("stop sync successfully"); 371 } 372 }); 373 ``` 374 375### getLastSyncTime<sup>12+</sup> 376 377getLastSyncTime(): Promise<number> 378 379异步方法获取上次同步时间, 以promise形式返回结果。 380 381**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 382 383**返回值:** 384 385| 类型 | 说明 | 386| --------------------- | ---------------- | 387| Promise<number> | 使用Promise形式返回上次同步时间。 | 388 389**错误码:** 390 391以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 392 393| 错误码ID | 错误信息 | 394| ---------------------------- | ---------- | 395| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 396| 202 | Permission verification failed, application which is not a system application uses system API. | 397| 401 | The input parameter is invalid. Possible causes:Incorrect parameter types. | 398| 13600001 | IPC error. | 399 400**示例:** 401 402 ```ts 403 import { BusinessError } from '@kit.BasicServicesKit'; 404 let fileSync = new cloudSync.FileSync(); 405 406 fileSync.getLastSyncTime().then((timeStamp: number) => { 407 let date = new Date(timeStamp); 408 console.info("get last sync time successfully:"+ date); 409 }).catch((err: BusinessError) => { 410 console.error("get last sync time failed with error message: " + err.message + ", error code: " + err.code); 411 }); 412 413 ``` 414 415### getLastSyncTime<sup>12+</sup> 416 417getLastSyncTime(callback: AsyncCallback<number>): void 418 419异步方法获取上次同步时间, 以callback形式返回结果。 420 421**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 422 423**参数:** 424 425| 参数名 | 类型 | 必填 | 说明 | 426| ---------- | ------ | ---- | ---- | 427| callback | AsyncCallback<number> | 是 | 异步获取上次同步时间的回调。| 428 429**错误码:** 430 431以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 432 433| 错误码ID | 错误信息 | 434| ---------------------------- | ---------- | 435| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 436| 202 | Permission verification failed, application which is not a system application uses system API. | 437| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 438| 13600001 | IPC error. | 439 440**示例:** 441 442 ```ts 443 import { BusinessError } from '@kit.BasicServicesKit'; 444 let fileSync = new cloudSync.FileSync(); 445 446 fileSync.getLastSyncTime((err: BusinessError, timeStamp: number) => { 447 if (err) { 448 console.error("get last sync time with error message: " + err.message + ", error code: " + err.code); 449 } else { 450 let date = new Date(timeStamp); 451 console.info("get last sync time successfully:"+ date); 452 } 453 }); 454 ``` 455 456## CloudFileCache<sup>11+</sup> 457 458云盘文件缓存对象,用来支撑文件管理应用原文件下载流程。 459 460**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 461 462### construct<sup>11+</sup> 463 464constructor() 465 466云盘文件缓存流程的构造函数,用于获取CloudFileCache类的实例。 467 468**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 469 470**错误码:** 471 472| 错误码ID | 错误信息 | 473| ---------------------------- | ---------- | 474| 401 | The input parameter is invalid. Possible causes:Incorrect parameter types. | 475 476**示例:** 477 478 ```ts 479 let fileCache = new cloudSync.CloudFileCache(); 480 ``` 481 482### on<sup>11+</sup> 483 484on(event: 'progress', callback: Callback\<DownloadProgress>): void 485 486添加云盘文件缓存过程事件监听。 487 488**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 489 490**参数:** 491 492| 参数名 | 类型 | 必填 | 说明 | 493| ---------- | ------ | ---- | ---- | 494| event | string | 是 | 订阅的事件类型,取值为'progress'(下载过程事件)。| 495| callback | Callback\<[DownloadProgress](#downloadprogress11)> | 是 | 云文件下载过程事件回调。 | 496 497**错误码:** 498 499以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 500 501| 错误码ID | 错误信息 | 502| ---------------------------- | ---------- | 503| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 504| 13600001 | IPC error. | 505 506**示例:** 507 508 ```ts 509 import { BusinessError } from '@kit.BasicServicesKit'; 510 let fileCache = new cloudSync.CloudFileCache(); 511 let callback = (pg: cloudSync.DownloadProgress) => { 512 console.info("download state:" + pg.state); 513 }; 514 515 try { 516 fileCache.on('progress', callback); 517 } catch (e) { 518 const error = e as BusinessError; 519 console.error(`Error code: ${error.code}, message: ${error.message}`); 520 } 521 ``` 522 523### off<sup>11+</sup> 524 525off(event: 'progress', callback?: Callback\<DownloadProgress>): void 526 527移除云盘文件缓存过程事件监听。 528 529**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 530 531**参数:** 532 533| 参数名 | 类型 | 必填 | 说明 | 534| ---------- | ------ | ---- | ---- | 535| event | string | 是 | 取消订阅的事件类型,取值为'progress'(同步过程事件)。| 536| callback | Callback\<[DownloadProgress](#downloadprogress11)> | 否 | 云文件下载过程事件回调。若填写,将视为取消指定的回调函数;否则为取消当前订阅的所有回调函数。 | 537 538**错误码:** 539 540以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 541 542| 错误码ID | 错误信息 | 543| ---------------------------- | ---------- | 544| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 545| 13600001 | IPC error. | 546 547**示例:** 548 549 ```ts 550 import { BusinessError } from '@kit.BasicServicesKit'; 551 let fileCache = new cloudSync.CloudFileCache(); 552 553 let callback = (pg: cloudSync.DownloadProgress) => { 554 console.info("download state:" + pg.state); 555 } 556 557 try { 558 fileCache.on('progress', callback); 559 fileCache.off('progress', callback); 560 } catch (e) { 561 const error = e as BusinessError; 562 console.error(`Error code: ${error.code}, message: ${error.message}`); 563 } 564 ``` 565 566### start<sup>11+</sup> 567 568start(uri: string): Promise<void> 569 570异步方法启动云盘文件缓存,以Promise形式返回结果。 571 572**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 573 574**参数:** 575 576| 参数名 | 类型 | 必填 | 说明 | 577| ---------- | ------ | ---- | ---- | 578| uri | string | 是 | 待下载文件uri。 | 579 580**返回值:** 581 582| 类型 | 说明 | 583| --------------------- | ---------------- | 584| Promise<void> | 使用Promise形式返回启动云文件下载的结果。 | 585 586**错误码:** 587 588以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 589 590| 错误码ID | 错误信息 | 591| ---------------------------- | ---------- | 592| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 593| 13600001 | IPC error. | 594| 13900002 | No such file or directory. | 595| 13900025 | No space left on device. | 596| 14000002 | Invalid uri. | 597 598**示例:** 599 600 ```ts 601 import { BusinessError } from '@kit.BasicServicesKit'; 602 import { fileUri } from '@kit.CoreFileKit'; 603 let fileCache = new cloudSync.CloudFileCache(); 604 let path = "/data/storage/el2/cloud/1.txt"; 605 let uri = fileUri.getUriFromPath(path); 606 607 try { 608 fileCache.on('progress', (pg: cloudSync.DownloadProgress) => { 609 console.info("download state:" + pg.state); 610 }); 611 } catch (e) { 612 const error = e as BusinessError; 613 console.error(`Error code: ${error.code}, message: ${error.message}`); 614 } 615 616 fileCache.start(uri).then(() => { 617 console.info("start download successfully"); 618 }).catch((err: BusinessError) => { 619 console.error("start download failed with error message: " + err.message + ", error code: " + err.code); 620 }); 621 ``` 622 623### start<sup>11+</sup> 624 625start(uri: string, callback: AsyncCallback<void>): void 626 627异步方法启动云盘文件缓存,以callback形式返回结果。 628 629**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 630 631**参数:** 632 633| 参数名 | 类型 | 必填 | 说明 | 634| ---------- | ------ | ---- | ---- | 635| uri | string | 是 | 待下载文件uri。 | 636| callback | AsyncCallback<void> | 是 | 异步启动云文件下载的回调。 | 637 638**错误码:** 639 640以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 641 642| 错误码ID | 错误信息 | 643| ---------------------------- | ---------- | 644| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 645| 13600001 | IPC error. | 646| 13900002 | No such file or directory. | 647| 13900025 | No space left on device. | 648| 14000002 | Invalid uri. | 649 650**示例:** 651 652 ```ts 653 import { BusinessError } from '@kit.BasicServicesKit'; 654 import { fileUri } from '@kit.CoreFileKit'; 655 let fileCache = new cloudSync.CloudFileCache(); 656 let path = "/data/storage/el2/cloud/1.txt"; 657 let uri = fileUri.getUriFromPath(path); 658 659 fileCache.start(uri, (err: BusinessError) => { 660 if (err) { 661 console.error("start download failed with error message: " + err.message + ", error code: " + err.code); 662 } else { 663 console.info("start download successfully"); 664 } 665 }); 666 ``` 667 668### stop<sup>11+</sup> 669 670stop(uri: string, needClean?: boolean): Promise<void> 671 672异步方法停止云盘文件缓存,以Promise形式返回结果。 673 674调用stop接口,当前文件下载流程会终止,缓存文件会被删除,再次调用start接口会重新开始下载。 675 676**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 677 678**参数:** 679 680| 参数名 | 类型 | 必填 | 说明 | 681| ---------- | ------ | ---- | ---- | 682| uri | string | 是 | 待下载文件uri。 | 683| needClean<sup>12+</sup> | boolean | 否 | 是否删除已下载的文件。默认值为false表示删除;true表示不删除。<br>从API version12开始支持该参数。 | 684 685**返回值:** 686 687| 类型 | 说明 | 688| --------------------- | ---------------- | 689| Promise<void> | 使用Promise形式返回停止云文件下载的结果。 | 690 691**错误码:** 692 693以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 694 695| 错误码ID | 错误信息 | 696| ---------------------------- | ---------- | 697| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 698| 13600001 | IPC error. | 699| 13900002 | No such file or directory. | 700| 14000002 | Invalid URI. | 701 702**示例:** 703 704 ```ts 705 import { BusinessError } from '@kit.BasicServicesKit'; 706 import { fileUri } from '@kit.CoreFileKit'; 707 let fileCache = new cloudSync.CloudFileCache(); 708 let path = "/data/storage/el2/cloud/1.txt"; 709 let uri = fileUri.getUriFromPath(path); 710 711 fileCache.stop(uri, true).then(() => { 712 console.info("stop download successfully"); 713 }).catch((err: BusinessError) => { 714 console.error("stop download failed with error message: " + err.message + ", error code: " + err.code); 715 }); 716 ``` 717 718### stop<sup>11+</sup> 719 720stop(uri: string, callback: AsyncCallback<void>): void 721 722异步方法停止云盘文件缓存,以callback形式返回结果。 723 724调用stop接口,当前文件下载流程会终止,缓存文件会被删除,再次调用start接口会重新开始下载。 725 726**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 727 728**参数:** 729 730| 参数名 | 类型 | 必填 | 说明 | 731| ---------- | ------ | ---- | ---- | 732| uri | string | 是 | 待下载文件uri。 | 733| callback | AsyncCallback<void> | 是 | 异步停止云文件下载的回调。 | 734 735**错误码:** 736 737以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 738 739| 错误码ID | 错误信息 | 740| ---------------------------- | ---------- | 741| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 742| 13600001 | IPC error. | 743| 13900002 | No such file or directory. | 744| 14000002 | Invalid URI. | 745 746**示例:** 747 748 ```ts 749 import { BusinessError } from '@kit.BasicServicesKit'; 750 import { fileUri } from '@kit.CoreFileKit'; 751 let fileCache = new cloudSync.CloudFileCache(); 752 let path = "/data/storage/el2/cloud/1.txt"; 753 let uri = fileUri.getUriFromPath(path); 754 755 fileCache.stop(uri, (err: BusinessError) => { 756 if (err) { 757 console.error("stop download failed with error message: " + err.message + ", error code: " + err.code); 758 } else { 759 console.info("stop download successfully"); 760 } 761 }); 762 ``` 763 764## DownloadErrorType<sup>11+</sup> 765 766端云下载错误类型,为枚举类型。 767 768**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 769 770| 名称 | 值| 说明 | 771| ----- | ---- | ---- | 772| NO_ERROR | 0 | 没有错误。 | 773| UNKNOWN_ERROR | 1 | 未知错误。 | 774| NETWORK_UNAVAILABLE | 2 | 网络不可用。 | 775| LOCAL_STORAGE_FULL | 3 | 本地空间不足。 | 776| CONTENT_NOT_FOUND | 4 | 云端空间未找到对应文件。 | 777| FREQUENT_USER_REQUESTS | 5 | 用户请求过于频繁。 | 778 779## cloudSync.registerChange<sup>12+</sup> 780 781registerChange(uri: string, recursion: boolean, callback: Callback<ChangeData>): void 782 783订阅监听指定文件的变化通知。 784 785**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 786 787**参数:** 788 789| 参数名 | 类型 | 必填 | 说明 | 790| ---------- | ------ | ---- | ---- | 791| uri | string | 是 | 待下载文件uri。 | 792| recursion | boolean | 是 | true为监听该uri以及子文件和子目录,false为仅监听该uri文件。| 793| callback | Callback<[ChangeData](#changedata12)> | 是 | 返回更改的数据。 | 794 795**错误码:** 796 797以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 798 799| 错误码ID | 错误信息 | 800| ---------------------------- | ---------- | 801| 202 | Permission verification failed, application which is not a system application uses system API. | 802| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 803| 13900001 | Operation not permitted. | 804| 13900002 | No such file or directory. | 805| 13900012 | Permission denied. | 806| 14000002 | Invalid URI. | 807 808**示例:** 809 810 ```ts 811 import { fileUri } from '@kit.CoreFileKit'; 812 let path = "/data/storage/el2/cloud/1.txt"; 813 let uri = fileUri.getUriFromPath(path); 814 let onCallback1 = (changeData: cloudSync.ChangeData) => { 815 if (changeData.type == cloudSync.NotifyType.NOTIFY_ADDED) { 816 //file had added, do something 817 } else if (changeData.type== cloudSync.NotifyType.NOTIFY_DELETED) { 818 //file had removed, do something 819 } 820 } 821 cloudSync.registerChange(uri, false, onCallback1); 822 // 取消注册监听 823 cloudSync.unregisterChange(uri); 824 ``` 825 826## cloudSync.unregisterChange<sup>12+</sup> 827 828unregisterChange(uri: string): void 829 830取消订阅监听指定文件的变化通知。 831 832**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 833 834**参数:** 835 836| 参数名 | 类型 | 必填 | 说明 | 837| ---------- | ------ | ---- | ---- | 838| uri | string | 是 | 待下载文件uri。 | 839 840**错误码:** 841 842以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 843 844| 错误码ID | 错误信息 | 845| ---------------------------- | ---------- | 846| 202 | Permission verification failed, application which is not a system application uses system API. | 847| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 848| 13900001 | Operation not permitted. | 849| 13900002 | No such file or directory. | 850| 13900012 | Permission denied. | 851| 14000002 | Invalid URI. | 852 853**示例:** 854 855 ```ts 856 import { fileUri } from '@kit.CoreFileKit'; 857 let path = "/data/storage/el2/cloud/1.txt"; 858 let uri = fileUri.getUriFromPath(path); 859 let onCallback1 = (changeData: cloudSync.ChangeData) => { 860 if (changeData.type == cloudSync.NotifyType.NOTIFY_ADDED) { 861 //file had added, do something 862 } else if (changeData.type== cloudSync.NotifyType.NOTIFY_DELETED) { 863 //file had removed, do something 864 } 865 } 866 cloudSync.registerChange(uri, false, onCallback1); 867 // 取消注册监听 868 cloudSync.unregisterChange(uri); 869 ``` 870 871## NotifyType<sup>12+</sup> 872 873数据变更通知类型。 874 875**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 876 877| 名称 | 值| 说明 | 878| ----- | ---- | ---- | 879| NOTIFY_ADDED | 0 | 文件已新建。 | 880| NOTIFY_MODIFIED | 1 | 文件已修改。 | 881| NOTIFY_DELETED | 2 | 文件已被删除。 | 882| NOTIFY_RENAMED | 3 | 文件被重命名或者移动。 | 883 884## ChangeData<sup>12+</sup> 885 886定义变更数据。 887 888**系统能力**:SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 889 890| 名称 | 类型 | 必填 | 说明 | 891| ---------- | ------ | ---- | ---- | 892| type | [NotifyType](#notifytype12) | 是 | 更改的通知类型。| 893| isDirectory | Array<boolean> | 是 | 指示更改的uri是否为目录。| 894| uris | Array<string> | 是 | 更改的uris。| 895