There are many options. Two of the most used ones are:
1. You can use File Metadata
in Firebase Storage to get the file name from URL. Basically, you create a Firebase Data Reference and then add a file metadata listener, like this:
// Create a storage reference from our app
StorageReference storageRef = storage.getReference();
// Get reference to the file
StorageReference fileRef = storageRef.child("images/forest.jpg");
fileRef.getMetadata().addOnSuccessListener(new OnSuccessListener<StorageMetadata>() {
@Override
public void onSuccess(StorageMetadata storageMetadata) {
String filename = storageMetadata.getName();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Uh-oh, an error occurred!
}
});
This code was taken from the documentation which I advice you to check out: File Metadata
2. Another option is to store your URL with the name in Firebase Database
. This has the advantage of avoiding unnecessary listeners. That means that you can get the name with a single value event listener without having to load all of the file metadata.
database.child("files").child("url")
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String name = dataSnapShot.getValue(String.class);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
}
It depends on your implementation on how you want to do it. Hope it helps :)