user6650650 user6650650 - 1 month ago 29
Android Question

Firebase uploaded file path

I would like to save uploaded file path to database. For this, Firebase gives me URI of uploaded file :

taskSnapshot.getDownLoadUrl()
. Now I need to save this to database for later use. What is the the correct way to save it as ? :

taskSnapshot.getDownLoadUrl().toString
or
taskSnapshot.getDownLoadUrl().getPath()
?

For testing I tried to load (Glide) the uploaded image file into an imageview using these strings above as load() method parameter. toString works but getPath doesn't.

Answer

When you get the downloadUrl of the taskSnapshot it returns an uri, if you then use toString() you get a string that contains the download url of the image, but if you ask for the path, it will return nothing, since the uri returned by taskSnapShot.getDownloadUrl() is not hierarchical. If you want the file path on firebase storage to access it via storage reference and not URL, you can use taskSnapshot.getStorage().