Firebase Storage and Android images
13,585
Solution 1
You need to use StorageReference
to load Firebase storage image.
// Reference to an image file in Cloud Storage
StorageReference storageReference = = FirebaseStorage.getInstance().getReference().child("myimage");
ImageView image = (ImageView)findViewById(R.id.imageView);
// Load the image using Glide
Glide.with(this /* context */)
.using(new FirebaseImageLoader())
.load(storageReference)
.into(image );
For more details You can check Using FirebaseUI to download and display images.
Solution 2
Put this class FirebaseImageLoader.java into your source, or write yourself.
Make a class anywhere in your app source like below.
@GlideModule
public class MyAppGlideModule extends AppGlideModule {
@Override
public void registerComponents(Context context, Glide glide, Registry registry) {
// Register FirebaseImageLoader to handle StorageReference
registry.append(StorageReference.class, InputStream.class,
new FirebaseImageLoader.Factory());
}
}
Where you want to load image coad like below.
StorageReference storageReference = FirebaseStorage
.getInstance().getReference().child("myimage");
Glide.with(getApplicationContext())
.load(completeStorageRefranceToImage)
.into(imageView);
Please refer for more details.
Author by
Alexei Sapozhnikov
Updated on June 09, 2022Comments
-
Alexei Sapozhnikov almost 2 years
So I want to basically get an image from Firebase storage (I have rules set to public).
This is what I have
ImageView image = (ImageView)findViewById(R.id.imageView); Glide.with(this) .load("https://firebasestorage.googleapis.com/v0/b/test-7c916.appspot.com/o/images.jpg?alt=media&token=b207cb11-9ad5-48e3-86ac-1dcb07ee6013") .into(image);
And I instead of using an https link. I want to use a storage reference. But everytime I try to use a storage reference my app crashes. Please help.
Like the .child() method.
-
Frank van Puffelen about 7 yearsWhile using a
StorageReference
from the Firebase SDK is indeed one way to download from Cloud Storage, there is also a publicly readable, unguessable download URL. That's what Alexei is using here, so it should work with any library that can download from HTTPS. -
pRaNaY about 7 yearsThank you sir for more info about to access Firebase storage. So for Alexei case, we need to figure out why app getting crash.
-
Smac over 6 yearsWhen I try this FirebaseImageLoader does not show up in blue? I cannot use it? My app is xamarin.android only
-
Dumbo about 6 years@pRaNaY Could you tell me which version and what type of
Glide
library should I use? Now I have triedglide-full-4.6.1.jar
andglide-full-4.5.0.jar
, but there isn't such a methodusing()
and classFirebaseImageLoader()
... -
Milos Simic Simo almost 5 yearsSmall note: Also clean project, then do build. After that all should work.