Unable to get download url from firebase storage


Pannan

I can upload the image successfully but can't get the URL of the uploaded image Also with the recent changes to the method I would like to write a cleaner code than this.

try {
          await FirebaseStorage.instance
              .ref()
              .child('user_image')
              .child(authResult.user
                      .uid + //ref gives access to root cloud store , firebase manages all the tokens etc
                  '.jpg')
              .putFile(image);
        } on FirebaseException catch (e) {
          print(e);
        }
        //Download the Url
        String url = await FirebaseStorage.instance
            .ref()
            .child('user_image')
            .child(authResult.user
                    .uid + //ref gives access to root cloud store , firebase manages all the tokens etc
                '.jpg')
            .getDownloadURL();
        print('Url' + url);


Frank Van Pferen

You don't need to use an UploadTaskto get the download URL. A simpler version of the code is:

Reference ref = FirebaseStorage.instance .ref()
  .child('user_image')
  .child(authResult.user.uid+'.jpg')
try {
  await ref.putFile(image);
  String url = await ref.getDownloadURL();
  print('Url' + url);
} on FirebaseException catch (e) {
  print(e);
}

What I did above:

  1. To create a variable StorageReferenceso you only have to calculate it once, upload and get the download URL from that variable.
  2. Move exception handling to override the getDownloadURL()call, as you probably don't want to try to get the download URL if the upload fails.

With these two changes, it's pretty idiomatic and very close to the FlutterFire documentation examples on uploading files and getting download URLs .

Related


Get download URL from Firebase Storage in Angular

Monther I'm trying to get the download URL after uploading a file to Firebase Storage, so far I've been able to upload the file, but for the URL, I've been getting undefined, this is my code: onFileChanged(event) { const file: File = event.target.files[0];

Get download URL from Firebase Storage in Angular

Monther I'm trying to get the download URL after uploading a file to Firebase Storage, so far I've been able to upload the file, but for the URL, I've been getting undefined, this is my code: onFileChanged(event) { const file: File = event.target.files[0];

Error trying to get download URL from firebase-storage

Alec Janiak I've been trying to get the download URL of an image in my firebase storage, but it keeps throwing object-does-not-exist errors. Any clue what could be the problem? I'm sure the directories match and there is a profilePhoto.jpg file in the firebase

Get download URL of Firebase Storage file

birdcage I have a mobile app that requires Firebase registration to backup/restore custom user data in Firebase. I would like to know if an authorized user can somehow get the url of his own stored file and download it to his computer. Frank Vampfelen If a use

The URL to download from Firebase Storage is empty

Mobilize IT I am using Ionic 4 to upload images from camera to firebase storage. The upload works fine, but I'm having trouble getting the upload URL. My code looks like this: async getFromCamera(){ this.camera.getPicture({ destinationType: this.came

Problem getting download URL from Firebase Storage

Gjison Giocf I'm trying to loop through the files in my game folder on firebase and display them on a page in a list format. // Create a reference under which you want to list var listRef = firebase.storage().ref("games/");; // Find all the prefixes and items

Problem getting download URL from Firebase Storage

Gjison Giocf I'm trying to loop through the files in my game folder on firebase and display them on a page in a list format. // Create a reference under which you want to list var listRef = firebase.storage().ref("games/");; // Find all the prefixes and items

The URL to download from Firebase Storage is empty

Mobilize IT I am using Ionic 4 to upload images from camera to firebase storage. The upload works fine, but I'm having trouble getting the upload URL. My code looks like this: async getFromCamera(){ this.camera.getPicture({ destinationType: this.came

Problem getting download URL from Firebase Storage

Gjison Giocf I'm trying to loop through the files in my game folder on firebase and display them on a page in a list format. // Create a reference under which you want to list var listRef = firebase.storage().ref("games/");; // Find all the prefixes and items

Problem getting download URL from Firebase Storage

Gjison Giocf I'm trying to loop through the files in my game folder on firebase and display them on a page in a list format. // Create a reference under which you want to list var listRef = firebase.storage().ref("games/");; // Find all the prefixes and items

Problem getting download URL from Firebase Storage

Gjison Giocf I'm trying to loop through the files in my game folder on firebase and display them on a page in a list format. // Create a reference under which you want to list var listRef = firebase.storage().ref("games/");; // Find all the prefixes and items

Unable to get URL of uploaded image on Firebase Storage

Mahendra class FCMStorage { var storage: Storage! init() { storage = Storage.storage() } func storeImage(data: Data?, name: String, completion: @escaping ((String?, Error?)->Void)) { guard let data = data else { return } let metaDat

Unable to get URL of uploaded image on Firebase Storage

Mahendra class FCMStorage { var storage: Storage! init() { storage = Storage.storage() } func storeImage(data: Data?, name: String, completion: @escaping ((String?, Error?)->Void)) { guard let data = data else { return } let metaDat