I have image view which loads image using Glide using download link. Code is given below :
How can I get the file name stored in fire base storage from the download url ?
Glide.with(ct)
.load(downloadurllink)
.centerCrop();
placeholder(R.drawable.common_icon_dark)
.into(holder.image);
You can get filename easily using the name property. Example:
val httpsReference = FirebaseStorage.getInstance().getReferenceFromUrl("https://firebasestorage.googleapis.com/v0/b/art-
track.appspot.com/o/images%2Fu1nffhbfdjsa%2FN11vSOYorUM2%2FImageName.JPG?
alt=media&token=86081f67-9065-4a13-aa0b-14fab7d44bf3")
Log.d(TAG, "filename: ${httpsReference.name}")
Android Example:
StorageReference storageReference = FirebaseStorage.getInstance().getReferenceFromUrl(urlImg);
String link = storageReference.getName();
Toast.makeText(EditAQuestionP1.this, link, Toast.LENGTH_SHORT).show();
I had the same problem and I used a Regular Expression to extract the file name from the download URL
%2..*%2F(.*?)\?alt
Eg: If your download URL is https://firebasestorage.googleapis.com/v0/b/art-track.appspot.com/o/images%2Fu1nffdGQ7QPLIMp7N11vSOYorUM2%2FCapture.JPG?alt=media&token=86081f67-9065-4a13-aa0b-14fab7d44bf3
, by using %2..*%2F(.*?)\?alt
you can extract "Capture.JPG"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With