The **cloudSync** module provides the device-cloud synchronization capabilities for applications. You can use the APIs to start or stop device-cloud synchronization and start or stop the download of images.
> **NOTE**
>
> - 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.
> - The APIs of this module are system APIs and cannot be called by third-party applications.
## Modules to Import
```js
importcloudSyncfrom'@ohos.file.cloudSync'
```
## SyncState
Enumerates the device-cloud synchronization states.
> **NOTE**
>
> If a synchronization process event listener is registered for an application, a callback will be invoked to notify the application when any of the following states is changed.
Enumerates the device-cloud synchronization error types.
- Currently, **NETWORK_UNAVAILABLE** is returned only when both the mobile network and Wi-Fi are unavailable during synchronization. If either network is available, synchronization can be performed normally.
- During the synchronization 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.
- When synchronization is triggered, if the battery level is lower than 15% in non-charging scenarios, synchronization is not allowed and an error code will be returned by **start()**.
- If the cloud space is insufficient when a file is uploaded, the upload will fail.
- 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 synchronization starts.
Provides APIs to implement device-cloud synchronization of media resources of the Gallery. Before using the APIs of **GallerySync**, you need to create a **GallerySync** instance.
### constructor
constructor()
A constructor used to create a **GallerySync** instance.
| evt | string | Yes | Type of the event to subscribe to. The value is **progress**, which indicates the synchronization process event.|
| callback | (pg: SyncProgress) => void | Yes | Callback invoked to return the result. The input parameter is [SyncProgress](#syncprogress), and the return value is **void**.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
**Example**
```js
letgallerySync=newcloudSync.GallerySync();
gallerySync.on('progress',(pg:SyncProgress)=>{
console.info("syncState: "+pg.syncState);
});
```
### off
off(evt: 'progress'): void
Unsubscribes from the synchronization process event.
| evt | string | Yes | Type of the event to subscribe to. The value is **progress**, which indicates the download process event.|
| callback | (pg: DownloadProgress) => void | Yes | Callback invoked to return the result. The input parameter is [DownloadProgress](#downloadprogress), and the return value is **void**.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| uri | string | Yes | URI of the file to download.|
| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13900002 | No such file or directory. |
| 13900025 | No space left on device. |
**Example**
```js
letdownload=newcloudSync.Download();
download.start((err)=>{
if(err){
console.info("start download failed with error message: "+err.message+", error code: "+err.code);
}else{
console.info("start download successfully");
}
});
```
### stop
stop(uri: string): Promise<void>
Stops downloading a cloud file. This API uses a promise to return the result.
> **NOTE**
>
> Calling **stop** will terminate the download of the current file and clear the cached file. You can use [start](#start-3) to start the download again.
Stops downloading a cloud file. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Calling **stop** will terminate the download of the current file and clear the cached file. You can use [start](#start-4) to start the download again.
The **cloudSyncManager** module provides APIs for changing the cloud and device service status and notifying the data changes.
The **cloudSyncManager** module provides APIs for managing device-cloud synergy for applications. You can use the APIs to enable or disable device-cloud synergy, change the device-cloud synchronization switch for an application, notify cloud data changes, and clear or retain cloud files when a cloud account exits.
> **NOTE**
> **NOTE**
>
> - 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.
> - 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.
> - The APIs of this module are system APIs and cannot be called by third-party applications.
> - The APIs of this module are system APIs and cannot be called by third-party applications.
| switches | object | Yes | Whether to enable the device-cloud synergy feature. **bundleName** indicates the application bundle name. The switch status is a Boolean value.|
**Return value**
| Type | Description |
| --------------------- | ---------------- |
| Promise<void> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| switches | object | Yes | Whether to enable the device-cloud synergy feature. **bundleName** indicates the application bundle name. The switch status is a Boolean value.|
| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| appActions | object | Yes | Action to take. **bundleName** indicates the application bundle to clear, and [Action](#action) indicates the action to take.|
**Return value**
| Type | Description |
| --------------------- | ---------------- |
| Promise<void> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| appActions | object | Yes | Action to take. **bundleName** indicates the application bundle to clear, and [Action](#action) indicates the action to take.|
| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).