目录

Obtaining the Cloud File List

You can obtain information about all files in a specified cloud directory, including the file storage directory and file name.

Constraints

This feature supports phones and tablets by default. Starting from version 5.1.0(18), support for wearables is added. From version 5.1.1(19), TVs are also supported. From version 6.1.0(23), PCs/2-in-1 devices are supported as well.

Prerequisites

Procedure

  1. Import required modules.

    import { cloudStorage } from '@kit.CloudFoundationKit';
    // ...
    import { BusinessError } from '@kit.BasicServicesKit';
    import { hilog } from '@kit.PerformanceAnalysisKit';
  2. Call StorageBucket.list to obtain the list of files in a specified directory on the cloud.

    bucket.list('', {
      maxResults: 1,
    }).then((result: Object) => {
      hilog.info(0x0000, 'Storage', `Succeeded in listing file  ${JSON.stringify(result)}`);
    }).catch((err: BusinessError) => {
      hilog.error(0x0000, 'Storage', `Failed to list file  code: ${err.code}, message: ${err.message}`);
    });

    The structure of the obtained file list is as follows:

    {
      directories: ["empty-dir1\/", "screenshot\/"],
      files: ["IMG_20240229_103118.jpg", "IMG_20240318_093732.jpg"]
    }