简体   繁体   中英

How to get name of a file from the link of that file in firebasestorage in flutter dart

I am using firebase storage to store files in my flutter app i can get the download link of that file from the firebase storage ,but i want the name of that file after uploaded.what is the way to get it. it is an sample link of an .mp3 file generated by firebase storage.

https://firebasestorage.googleapis.com/v0/b/musicapp-002.appspot.com/o/song%20name%2Calbum%20name%2Cartist%20name%20by%20testing0%40gmail.com.mp3?alt=media&token=213b776c-5563-468a-9724-0f53d75aff90

and the file name is song name,album name,artist name by testing0@gmail.com so how to generate the filename from the given firebase storage link.

Try this :

String  link = "https://firebasestorage.googleapis.com/v0/b/musicapp-002.appspot.com/o/song%20name%2Calbum%20name%2Cartist%20name%20by%20testing0%40gmail.com.mp3?alt=media&token=213b776c-5563-468a-9724-0f53d75aff90";

link =  link.split("/")[7];
link = link.replaceAll("%20"," ");
link = link.replaceAll("%2C", ",");
link = link.substring(0, link.indexOf('.mp3'));
link = link.replaceAll("%40", "@");
print(link);

Output :

song name,album name,artist name by testing0%40gmail.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM