user6650650 user6650650 - 11 months ago 145
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 :

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


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 Source

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().