目录

Initializing a Storage Instance

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

You have enabled Cloud Storage.

Procedure

Call cloudStorage.bucket to initialize a storage instance.

  1. Import required modules.

    import { cloudStorage } from '@kit.CloudFoundationKit';
  2. Initialize the instance using either of the following methods:

    • Initializing the default instance

      let bucket: cloudStorage.StorageBucket = cloudStorage.bucket();
    • Initializing a specified instance

      let bucket: cloudStorage.StorageBucket = cloudStorage.bucket('bucket001-2wezr'); // Specify the bucket001-2wezr instance.

    If you choose to initialize a specified Cloud Storage instance, ensure that the instance exists on the cloud; otherwise, subsequent operations will result in an error indicating that the instance cannot be found. Create a storage instance on the cloud. For details, please refer to Managing Storage Instances.