openharmony 鸿蒙 js-apis-file-clouddiskmanager-sys

2026-08-25 浏览 (1)

@ohos.file.cloudDiskManager (Cloud Disk Management) (System API)

This module enables the File Manager to obtain the sync root information registered by third-party cloud disks.

NOTE

The initial APIs of this module are supported since API version 21. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import { cloudDiskManager } from '@kit.CoreFileKit';

SyncFolderAccessor

A sync root management class that enables the File Manager to access the sync root information registered by third-party cloud disks.

constructor

constructor()

A constructor used to create a SyncFolderAccessor instance.

System API: This is a system API.

System capability: SystemCapability.FileManagement.CloudDiskManager

Required permissions: ohos.permission.ACCESS_CLOUD_DISK_INFO

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
201Permission verification failed.
202Permission verification failed, application which is not a system application uses system API.

Example

import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
struct Index {
  build() {
    Column() {
      Button('constructor')
      .onClick(async() => {
          try {
            let syncFolderAccessor: cloudDiskManager.SyncFolderAccessor = new cloudDiskManager.SyncFolderAccessor();
          } catch (err) {
              let error: BusinessError = err as BusinessError;
              console.error(`SyncFolderAccessor constructor failed. Code: ${error.code}, message: ${error.message}`);
          }
      });
    }
  }
}

getAllSyncFolders

getAllSyncFolders(): Promise<Array<SyncFolder>>

Obtains information about all registered sync roots. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.FileManagement.CloudDiskManager

Required permissions: ohos.permission.ACCESS_CLOUD_DISK_INFO

Return value

TypeDescription
Promise<Array<SyncFolder>>Promise that returns the sync root list of all cloud disk applications.

Error codes

For details about the error codes, see Cloud Disk Management Error Codes and Universal Error Codes.

IDError Message
201Permission verification failed.
202Permission verification failed, application which is not a system application uses system API.
801Device not supported.
34400003IPC communication failed.
34400014Temporary failure, Retry is recommended (e.g., network issues).
34400015Cloud disk is not allowed on this device.

Example

import { BusinessError } from '@kit.BasicServicesKit';
const TAG: string = '[cloudDiskManager]';

try {
    console.info(TAG + `getAllSyncFolders start`);
    let syncFolderAccessor: cloudDiskManager.SyncFolderAccessor = new cloudDiskManager.SyncFolderAccessor();
    syncFolderAccessor.getAllSyncFolders().then((syncFolders) => {
        if (syncFolders) {
            console.info(TAG + `getAllSyncFolders success, length: ${syncFolders.length}`);
            for (let i = 0; i < syncFolders.length; ++i) {
                console.info(TAG + `syncFolders[${i}].path: ${syncFolders[i].path}`);
                console.info(TAG + `syncFolders[${i}].bundleName: ${syncFolders[i].bundleName}`);
                console.info(TAG + `syncFolders[${i}].state: ${syncFolders[i].state}`);
                if (syncFolders[i].displayNameResId) {
                    console.info(TAG + `syncFolders[${i}].displayNameResId: ${syncFolders[i].displayNameResId}`);
                }
                if (syncFolders[i].customAlias) {
                    console.info(TAG + `syncFolders[${i}].customAlias: ${syncFolders[i].customAlias}`);
                }
            }
        } else {
            console.info(TAG + `getAllSyncFolders failed`);
        }
    }).catch((e: BusinessError<object>) => {
        console.error(TAG + `getAllSyncFolders then catch err, code: ${e.code}, message: ${e.message}`);
    })
} catch (err) {
    let error: BusinessError = err as BusinessError;
    console.error(TAG + `getAllSyncFolders failed. code: ${error.code}, message: ${error.message}`);
}

SyncFolder

Encapsulates the sync root information.

System API: This is a system API.

System capability: SystemCapability.FileManagement.CloudDiskManager

NameTypeRead-OnlyOptionalDescription
pathstringNoNoURI of the sync root.
bundleNamestringNoNoBundle name of the sync root.
stateSyncFolderStateNoNoState of the sync root.
displayNameResIdnumberNoYesResource ID, which can be mapped to the alias displayed in the File Manager list. The default value is undefined.
customAliasstringNoYesCustom alias displayed in the File Manager list. The default value is undefined.

SyncFolderState

Enumerates the states of the sync root.

System API: This is a system API.

System capability: SystemCapability.FileManagement.CloudDiskManager

NameValueDescription
INACTIVE0The sync root is inactive.
ACTIVE1The sync root is active.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 js-apis-file-environment-sys

openharmony 鸿蒙 js-apis-file-fs

openharmony 鸿蒙 capi-clouddisk-clouddisk-pathinfo

openharmony 鸿蒙 capi-clouddisk-clouddisk-changesresult

openharmony 鸿蒙 capi-clouddisk-clouddisk-syncfolder

openharmony 鸿蒙 js-apis-fileShare

openharmony 鸿蒙 capi-fileio

openharmony 鸿蒙 js-apis-file-storage-statistics-sys

openharmony 鸿蒙 js-apis-file-cloudsyncmanager

openharmony 鸿蒙 js-apis-file-environment

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/fXpuUADN