Reputation: 419
I am trying to load an image from Firebase Storage using Kotlin and Glide. i added all the dependecies and apply plugin:
implementation 'com.firebaseui:firebase-ui-storage:6.2.0'
implementation 'com.google.firebase:firebase-storage-ktx:19.1.1'
implementation 'com.github.bumptech.glide:glide:4.8.0'
kapt 'com.github.bumptech.glide:compiler:4.9.0'
apply plugin: 'kotlin-kapt'
My code is as follows:
val storageRef = Firebase.storage.reference
val imageref = storageRef.child("test/test.jpg")
imagetest = findViewById(R.id.imageView5)
Glide.with(this)
.load(imageref)
.into(imagetest)
When running the code, the imageview which had a default image goes black indicating that the code is trying to retrieve something from Firebase Storage. but the imageView never populates the downloaded image. assuming the download actually happens.
Am I doing something wrong? my firebase Storage screenshot is below:
I have tested this a little bit more, and Glide seems to load images from HTTPS ok, regardless of where i pull the URL from. But cloud storage provide URL as GS://. so how do i convert the GS:// to HTTPS://?
Please help.
Upvotes: 1
Views: 3456
Reputation: 153
Here is the process where my problem fixed -
Step 1 - go to build.gradle(app) and add these dependency
implementation 'com.firebaseui:firebase-ui-storage:4.3.2'
implementation 'com.github.bumptech.glide:glide:4.x.x'
annotationProcessor 'com.github.bumptech.glide:compiler:4.x.x'
Step 2 - Create a java file
@GlideModule
public class MyAppGlideModule extends AppGlideModule {
@Override
public void registerComponents(Context context, Glide glide, Registry registry) {
registry.append(StorageReference.class, InputStream.class,
new FirebaseImageLoader.Factory());
}
}
Step 3 - Set image where you want
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference storageRef = storage.getReferenceFromUrl("gs://<your-app>/").child("folder"); //add .child(nested_folder) if nested folder occurs
GlideApp.with(context)
.load(storageRef.child(test_image.jpg))
.into(holder.thumbnail);
//that .load() will be load like .load(gs://<your_app/folder/test_image.jpg>)
Upvotes: 0
Reputation: 5634
The difference between the both:
GS URL:
gs://<your_project_id>.appspot.com/test/test.jpg
HTPPS URL:
https://firebasestorage.googleapis.com/v0/b/<your_project_id>.appspot.com/o/test%2Ftest.jpg
Upvotes: 0
Reputation: 419
I Figured it out.
imageref = Firebase.storage.reference.child("test/test.jpg")
imageref.downloadUrl.addOnSuccessListener {Uri->
val imageURL = Uri.toString()
imagetest = findViewById(R.id.imageView5)
Glide.with(this)
.load(imageURL)
.into(imagetest)
}
the 'downloadurl' statement actually converts the GS:// to HTTPS://
Upvotes: 3