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