How to get URL getDownloadURL from Firebase Storage


Jonathan Fager:

I'm trying to get "Long Persistent Download Links" for a file in a Firebase bucket. I have changed its permissions to

service firebase.storage {
  match /b/project-xxx.appspot.com/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}

My javacode looks like this:

private String niceLink (String date){
    String link;
    // Points to the root reference
    StorageReference storageRef = FirebaseStorage.getInstance().getReference();
    StorageReference dateRef = storageRef.child("/" + date+ ".csv");
    link = dateRef.getDownloadUrl().toString();
    return link;
}

When I run it, I get a uri link that looks like com.google.android.gms.tasks.zzh@xxx

Question 1. Can I get a download link from : https://firebasestorage.googleapis.com/v0/b/project-xxxx.appspot.com/o/20-5-2016.csv?alt= media&token= b5d45a7f-3ab7-4f9b-b661-3a2187adxxxx

When trying to get the link above, I changed the last line before returning like this:

private String niceLink (String date){
    String link;
    // Points to the root reference
    StorageReference storageRef = FirebaseStorage.getInstance().getReference();
    StorageReference dateRef = storageRef.child("/" + date+ ".csv");
    link = dateRef.getDownloadUrl().getResult().toString();
    return link;
}

However, when I do this, I get a 403 error and the app crashes. The console tells me this is the BC user not logged in/auth. "Please login before requesting token"

Question 2. How to solve this problem?

Benjamin Wulfe:

Please refer to the documentation for the download URL .

When you call getDownloadUrl(), the call is asynchronous and you must subscribe to the success callback to get the result:

// Calls the server to securely obtain an unguessable download Url
private void getUrlAsync (String date){
    // Points to the root reference
    StorageReference storageRef = FirebaseStorage.getInstance().getReference();
    StorageReference dateRef = storageRef.child("/" + date+ ".csv");
    dateRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>()
    {
        @Override
        public void onSuccess(Uri downloadUrl) 
        {                
           //do something with downloadurl
        } 
    });
}

This will return a public, unguessable download URL. If you're just uploading a file, this public url will be in the upload's success callback (you don't need to call other async methods after uploading).

However, if you just want to Stringrepresent the reference, you can call.toString()

// Returns a Uri of the form gs://bucket/path that can be used
// in future calls to getReferenceFromUrl to perform additional
// actions
private String niceRefLink (String date){
    // Points to the root reference
    StorageReference storageRef = FirebaseStorage.getInstance().getReference();
    StorageReference dateRef = storageRef.child("/" + date+ ".csv");
    return dateRef.toString();
}

Related


How to get URL getDownloadURL from Firebase Storage

Jonathan Fager I'm trying to get "Long Persistent Download Links" for a file in a Firebase bucket. I have changed its permissions to service firebase.storage { match /b/project-xxx.appspot.com/o { match /{allPaths=**} { allow read, write; } }

How to get URL getDownloadURL from Firebase Storage

Jonathan Fager: I'm trying to get "Long Persistent Download Links" for a file in a Firebase bucket. I have changed its permissions to service firebase.storage { match /b/project-xxx.appspot.com/o { match /{allPaths=**} { allow read, write; }

Unable to get URL from Firebase's getDownloadURL

Stern Shaw: I'm using Firebase storage to store images into it, the images are easily uploaded to the storage, but when I try to get the url of the image form Promise, it doesn't return any url. const imageSaveHandler = (e) => { e.preventDefault(); c

Unable to get URL from Firebase's getDownloadURL

Stern Shaw: I'm using Firebase storage to store images into it, the images are easily uploaded to the storage, but when I try to get the url of the image form Promise, it doesn't return any url. const imageSaveHandler = (e) => { e.preventDefault(); c

Unable to get URL from Firebase's getDownloadURL

Stern Shaw: I'm using firebase storage to store images into it, the images are easy to upload to the storage, but when I try to get the url of the image form Promise, it doesn't return any url. const imageSaveHandler = (e) => { e.preventDefault(); co

How to get Firebase Storage URL

Prasad: I'm sending FCM notifications with image links using a backend that I've written in the backend. Images are stored in Firebase Storage. I need to resolve the bucket path to a Url that can be used to create FCM notifications. There seems to be a Javascr

How to get Firebase Storage URL

Prasad: I'm sending FCM notifications with image links using a backend that I've written in the backend. Images are stored in Firebase Storage. I need to resolve the bucket path to a Url that can be used to create FCM notifications. There seems to be a Javascr

How to get Firebase Storage URL

Prasad: I'm sending FCM notifications with image links using a backend that I've written in the backend. Images are stored in Firebase Storage. I need to resolve the bucket path to a Url that can be used to create FCM notifications. There seems to be a Javascr

Flutter : getDownloadUrl (firebase storage)

killian I have a problem with my flutter application. I want to upload an image to firebase storage and get the URL but the getDownloadUrl method doesn't work. Here is my code : import 'package:firebase_storage/firebase_storage.dart' as firebase_storage; ...

Flutter : getDownloadUrl (firebase storage)

killian I have a problem with my flutter application. I want to upload an image to firebase storage and get the URL but the getDownloadUrl method doesn't work. Here is my code : import 'package:firebase_storage/firebase_storage.dart' as firebase_storage; ...

Flutter : getDownloadUrl (firebase storage)

killian I have a problem with my flutter application. I want to upload an image to firebase storage and get the URL but the getDownloadUrl method doesn't work. Here is my code : import 'package:firebase_storage/firebase_storage.dart' as firebase_storage; ...

Flutter : getDownloadUrl (firebase storage)

killian I have a problem with my flutter application. I want to upload an image to firebase storage and get the URL but the getDownloadUrl method doesn't work. Here is my code : import 'package:firebase_storage/firebase_storage.dart' as firebase_storage; ...

How to get image URL from firebase storage to firestore

Khalifa Hill I am trying to upload an image to Firebase and get the URL in Firestore. It did upload the image but didn't get the URL to Firestore. This is how I get the image. Future getImage1() async { // ignore: deprecated_member_use var firstImage =

How to get image URL from firebase storage to firestore

Khalifa Hill I am trying to upload an image to Firebase and get the URL in Firestore. It did upload the image but didn't get the URL to Firestore. This is how I get the image. Future getImage1() async { // ignore: deprecated_member_use var firstImage =

How to get image URL from firebase storage to firestore

Khalifa Hill I am trying to upload an image to Firebase and get the URL in Firestore. It did upload the image but didn't get the URL to Firestore. This is how I get the image. Future getImage1() async { // ignore: deprecated_member_use var firstImage =