Search code examples
javafirebasefirebase-storagefirebase-admin

How I can remove an object from firebase storage with java admin sdk


I have the storage location ( Like gs://xxxxxx.appspot.com/43B92kgk7nRtN9uaIGpCAMFF3mr1/2020-12-24 13:18:59.670092.jpg ) and want to delete the object via admin SDK from my spring boot application.

In all documents they talk about blob Id , bucket name and ... ( I don't have those information), tried to find those information via storage location uri but didn't succeed.

I wonder what would be the easiest solution to remove from storage with storage location uri


Solution

  • Here is my solution that I find by trial and error, by testing different bucket names , bolb names and blob ids. (bucket name , blob name or blob Id is not obvious in most of the documentations )

    I have used "xxxxxx.appspot.com" as bucket name , and "43B92kgk7nRtN9uaIGpCAMFF3mr1/2020-12-24 13:18:59.670092.jpg" as blob name with the follwing code to delete it from the storage

     Bucket bucket = StorageClient.getInstance().bucket("timeline-10.appspot.com");
     boolean result =  bucket.get("43B92kgk7nRtN9uaIGpCAMFF3mr1/2020-12-24 13:18:59.670092.jpg").delete();