Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get file name from download link in firebase storage?

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);
like image 755
snth Avatar asked Sep 06 '25 16:09

snth


2 Answers

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();
like image 73
Syed Umair Avatar answered Sep 09 '25 07:09

Syed Umair


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"

like image 31
notnavindu Avatar answered Sep 09 '25 07:09

notnavindu