Delete files with Cloud Storage for C++

After uploading files toCloud Storage, you can also delete them.

Note: By default, aCloud Storage for Firebase bucket requiresFirebase Authenticationto perform any action on the bucket's data or files. You can change yourFirebase Security Rules forCloud Storage toallow unauthenticated access for specific situations.However, for most situations, we strongly recommendrestricting access and setting up robust security rules(especially for production apps). Note that if you useGoogleApp Engine and have a defaultCloud Storage bucket with a nameformat of*.appspot.com, you may need to considerhow your security rules impact access toApp Engine files.

Delete a File

To delete a file, firstcreate a referenceto that file. Then call theDelete() method on that reference.

// Create a reference to the file to delete.StorageReference*desert_ref=storage_ref.Child("images/desert.jpg");// Delete the fileFuturefuture=desert_ref.Delete();// Wait for operation to complete...if(future.Error()!=firebase::storage::kErrorNone){// Uh-oh, an error occurred!}else{// File deleted successfully}
Note: Deleted files are typically recoverable for 7 days withsoft delete,which is enabled by default.

Handle Errors

There are a number of reasons why errors may occur on file deletes,including the file not existing, or the user not having permissionto delete the specified file. More information on errors can be found in theHandle Errorssection of the docs.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-17 UTC.