I need to access an image stored on Firebase Storage by a direct link, eg
http://myfirebasehost.com/storage/imgIwant.png
For all I know, it can only this type of URL using the protocol gs://
, however, it is not accessible by link, only in the SDK api.
I need a solution exactly as described above using the Firebase platform, if not possible, accept other suggestions.
My code has constants that are links to images. It turns out that if I want to update this picture, I have to make a new deployment. Instead I want to update the image at the same URL. It would be impossible to do this with the firebase (to my knowledge) because the URL provided by Storage is not accessible by link.
Another alternative might be to convert an image to base64 and stored in the database, but would be very extensive and impractical.
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.
How to translate your gs storage location
to a direct url
by example:
gs://nobs-f32f2.appspot.com/profile/1s_by_wlop-dc1sdan.jpg
becomes
https://firebasestorage.googleapis.com/v0/b/nobs-f32f2.appspot.com/o/profile%2F1s_by_wlop-dc1sdan.jpg?alt=media
1st
be sure to URL escape your blob path. For example, swap forward slashes (/
) for %2F and spaces () for %20.
2nd
be sure you've open read access where needed. Here is an open rule to get moving:
service firebase.storage { match /b/{bucket}/o { match /{allPaths=**} { allow read: if true; allow write: if request.auth != null; } } }
With Firebase Storage, you're given two URLs that you can use to represent files:
// "Private" internal URL, only accessible through Firebase Storage API // This is protected by Firebase Storage Security Rules & Firebase Auth gs://bucket/object // "Public" unguessable URL, accessible by anyone with the link // This is secured because that token is *very* hard for someone to guess https://firebasestorage.googleapis.com/v0/bucket/object?alt=media&token=<token>
The first option requires that you use the reference.getDownloadURL()
method to convert the internal gs://
URL into a public https://
URL.
The second option allows you to share this public but unguessable URL with trusted individuals, and allows them to access content without authentication to Firebase or using your app--think sharing family photos with Google Photos. Likely this behavior will be good enough, unless you desire public sharing with clean URLs. You can use this URL in a browser, or use any other HTTP library to download it. We provide the ability to download these files as well (off a reference), so you don't need to get a third party library, you can just use us.
I strongly recommend reading our docs for more information on this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With