目录

Obtaining Metadata of a Cloud File

File metadata includes common attributes such as the cloud file name, size, and type, as well as custom file attributes.

After a file is uploaded to the cloud, you can obtain the metadata of the file before downloading the file to determine whether to download the file.

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.getMetadata to obtain the metadata of a specified cloud file.

    let bucket: cloudStorage.StorageBucket = cloudStorage.bucket();
    bucket.getMetadata(UI.uploadFileName).then((result: cloudStorage.Metadata) => {
      hilog.info(0x0000, 'Storage', `promise bucket.getMetadata end  ${JSON.stringify(result)}`);
      let time: Date = result.createTime;
      hilog.info(0x0000, 'Storage', `printMessage time ${time}`);
      hilog.info(0x0000, 'Storage', `time ${time.getTime()}`);
    }).catch((err: BusinessError) => {
      hilog.error(0x0000, 'Storage', `Failed to getMetadata code: ${err.code}, message: ${err.message}`);
    });