Daggydag13 Daggydag13 - 1 year ago 184
Android Question

Convert uri to string with firebase storage

I get a simple example rom firebase how to upload image to storage. Upload fine, and when

i have uri to download something like this:


When i try to convert this uri to string i have
, wat's wrong?

Uri downloadUrl = taskSnapshot.getMetadata().getDownloadUrl();
String string_dwload = downloadUrl.toString();//valueOf not work too

Answer Source

You need to change your code by calling method getDownloadUrl() on the taskSnapshot object (instead of getMetadata()) - so your code in the onSuccess callback should look like this:

public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
        //get the download URL like this:
        Uri downloadUrl = taskSnapshot.getDownloadUrl();
        //and you can convert it to string like this:
        String string_dwload = downloadUrl.toString();        

I hope this helps. By the way, please check the article/tutorial on Uploading file on Android