Reputation: 79
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.
Upvotes: 4
Views: 14074
Reputation: 318
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.
Upvotes: 1
Reputation: 79
So used pRaNaY's code like this
StorageReference storageReference = FirebaseStorage.getInstance().getReference().child("images.jpg");
ImageView image = (ImageView)findViewById(R.id.imageView);
Glide.with(this).using(new FirebaseImageLoader()).load(storageReference).into(image );
There reason I want to use a reference is because I will have names of all the images in a txt file and I will read the names of images from it and create a while loop to load all the images I need into the right place.
Just one more question, How do i know if the image is null without checking if the ImageView is null?
Upvotes: 0
Reputation: 25320
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.
Upvotes: 6