Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Download URL from Firebase Storage in Flutter

I'm currently exploring Flutter, I found there is an official Firebase Storage plugin in Flutter firebase_storage I have storage reference like this one:

final StorageReference ref = FirebaseStorage.instance.ref().child("default.png");

But there is no method to get download URL from that StorageReference.

like image 413
Putra Ardiansyah Avatar asked Jan 25 '18 03:01

Putra Ardiansyah


People also ask

How do I get the download URL from Firebase Storage in Flutter?

Download Data via URL If you already have download infrastructure based around URLs, or just want a URL to share, you can get the download URL for a file by calling the getDownloadURL() method on a Cloud Storage reference.

How can I get URL of uploaded image in Firebase Storage?

Image URL is obtained by uploading an image to firebase bucket and then that can return back a URL that URL is a permanent URL which can be open anywhere. Then a user can use this URL for any purpose in its application.


2 Answers

If the above solution doesn't work, try this:

Future<String> uploadImage(var imageFile ) async {
    StorageReference ref = storage.ref().child("/photo.jpg");
    StorageUploadTask uploadTask = ref.putFile(imageFile);

    var dowurl = await (await uploadTask.onComplete).ref.getDownloadURL();
    url = dowurl.toString();

    return url; 
}
like image 66
Alex Moon Avatar answered Sep 19 '22 16:09

Alex Moon


use url like this:

printUrl() async {
    StorageReference ref = 
        FirebaseStorage.instance.ref().child("images/sky.jpg");
    String url = (await ref.getDownloadURL()).toString();
    print(url);
}
like image 36
Dan Alboteanu Avatar answered Sep 16 '22 16:09

Dan Alboteanu