Delete files with Cloud Storage on Android

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 reference.to that file. Then call thedelete() method on that reference.

Kotlin

// Create a storage reference from our appvalstorageRef=storage.reference// Create a reference to the file to deletevaldesertRef=storageRef.child("images/desert.jpg")// Delete the filedesertRef.delete().addOnSuccessListener{// File deleted successfully}.addOnFailureListener{// Uh-oh, an error occurred!}

Java

// Create a storage reference from our appStorageReferencestorageRef=storage.getReference();// Create a reference to the file to deleteStorageReferencedesertRef=storageRef.child("images/desert.jpg");// Delete the filedesertRef.delete().addOnSuccessListener(newOnSuccessListener<Void>(){@OverridepublicvoidonSuccess(VoidaVoid){// File deleted successfully}}).addOnFailureListener(newOnFailureListener(){@OverridepublicvoidonFailure(@NonNullExceptionexception){// Uh-oh, an error occurred!}});
Note: Deleting a file is a permanent action! If you care about restoringdeleted files, make sure to back up your files, orenable Object Versioningon yourCloud Storage bucket.

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 desired 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-07-10 UTC.