【问题标题】:Unable to show image from firebase storage using Glide?无法使用 Glide 显示来自 Firebase 存储的图像?
【发布时间】:2017-05-09 04:50:10
【问题描述】:

我采用了两种方法来使用 glide 从 firebase 存储中获取图像。第一种方法运行良好,因为在获取 downloadUrl 后,它正在使用 glide 加载图像。

但第二个更方便,但它不适合我。

buidl.gradle:应用程序

  dependencies {
      // ..... not included glige dependency
      compile 'com.firebaseui:firebase-ui-storage:0.6.0'
  }

第一种方法(工作):

// question.imgQuestion  = "qimgs/-KiTpzP5t-xJOO5nSK0A/1493896460324-ch1pg2.jpg"
final StorageReference ref = mStorage.getReference().child(question.imgQuestion);

ref.getDownloadUrl().addOnSuccessListener(this, new OnSuccessListener<Uri>() {
    @Override
    public void onSuccess(Uri uri) {
       Log.i(TAG, "Download URL : " + uri); // https://firebasestorage.googleapis.com/v0/b/questionpaper-ce229.appspot.com/o/qimgs%2F-KiTpzP5t-xJOO5nSK0A%2F1493896460324-ch1pg2.jpg?alt=media&token=ca2a3f6e-3eb5-4088-a48d-069ac8ad640b
       Glide.with(QuizActivity.this)
                .load(uri)
                .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
                .into(mImageQuestion);
    }
});

第二种方法(不起作用,但我想要这个)

// question.imgQuestion  = "qimgs/-KiTpzP5t-xJOO5nSK0A/1493896460324-ch1pg2.jpg"
final StorageReference ref = mStorage.getReference().child(question.imgQuestion);
Glide.with(QuizActivity.this)
    .using(new FirebaseImageLoader())
    .load(ref)
    .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
    .into(mImageQuestion);

注意:此 Firebase 存储实例是经过身份验证的实例。

【问题讨论】:

  • 代码看起来不错。有任何错误信息吗?考虑添加RequestListener 以获得更多状态。请参阅此问题以获取示例代码:stackoverflow.com/q/43853592/4815718。您也可以尝试使用更新版本的 FirebaseUI 库。最新的是 1.2.0。
  • 谢谢,是库版本问题。使用 FirebaseUI 版本:1.2.0 和 Firebase/Play 服务版本:10.2.0。现在它正在工作。

标签: android image firebase firebase-storage android-glide


【解决方案1】:
StorageReference imagepath = storageReference.child("Images");   
 imagepath.putFile(selectedImage).addOnSuccessListener(new 
 OnSuccessListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {


                getimage = taskSnapshot.getDownloadUrl();

     Glide.with(QuizActivity.this)
.using(new FirebaseImageLoader())
.load(getimage)
.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
.into(mImageQuestion);
                }
            });

试试这个,这对我有用

【讨论】:

    【解决方案2】:

    我也遇到了这个问题,原来是最新版本的 firebase SDK (10.2.4) 导致了这个问题,所以我恢复到 10.2.1,一切都很好。

    【讨论】:

      【解决方案3】:

      .load(ref) 替换为.load(ref.getDownloadUrl())

      Glide.with(QuizActivity.this)
      .using(new FirebaseImageLoader())
      .load(ref.getDownloadUrl())
      .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
      .into(mImageQuestion);
      

      【讨论】:

      • 编译器不允许声明.load(ref.getDownloadUrl())
      • .load 方法将在参数中采用 firebase 存储对象。
      猜你喜欢
      • 2018-08-13
      • 2016-09-28
      • 2017-01-12
      • 2018-11-21
      • 2017-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-17
      相关资源
      最近更新 更多