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.
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.
You have initialized a storage instance.
You have uploaded a specified file to the cloud.
Import required modules.
import { cloudStorage } from '@kit.CloudFoundationKit';
// ...
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit'; 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}`);
});