目录

Deleting a Cloud File

A cloud file that is no longer needed can be deleted through the app client.

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.deleteFile to delete a file from the cloud.

    Deletion is irreversible. Once deleted, the file will be physically deleted and cannot be retrieved.

    let bucket: cloudStorage.StorageBucket = cloudStorage.bucket();
    bucket.deleteFile(UI.uploadFileName).then(() => {
      hilog.info(0x0000, 'Storage', `Succeeded in deleting File`);
    }).catch((err: BusinessError) => {
      hilog.error(0x0000, 'Storage', `Failed to delete file  code: ${err.code}, message: ${err.message}`);
    });

    After the file is deleted, you can sign in to AppGallery Connect, select a project, and go to the Cloud Storage page to view the file list.