【问题标题】:get image with picasso based on userId firebase基于 userId firebase 使用 picasso 获取图像
【发布时间】:2017-04-13 11:16:30
【问题描述】:

我正在尝试为用户个人资料上传和下载图片,当我保存照片时,我将其与 userId 一起保存,这样每次他更改照片时我都可以替换它,现在我需要的是获取该照片毕加索,问题是,我不知道如何获取照片,它可以有不同的格式和其他东西,如 jpeg、png,我只想在用户 ID 匹配时获取图像,我试过这个:

storageRef = storage.getReferenceFromUrl("gs://friendlymanager-3b7a2.appspot.com");

Picasso.with(UserSettings.this).load(storageRef + "/Photos/" + userId).into(userImage);

我的 userImage 是我的 imageView,我没有收到任何错误,只是一张空白图片,我已经为特定用户准备了一张照片。

有什么帮助吗?

【问题讨论】:

  • 您的链接是否返回图片?
  • 如何检查?
  • 记录您的最终网址。 Log.d("URL", storageRef + "/Photos/" + userId);
  • 在最终和不使用 .jpg 时尝试过,我得到一个纯字符串:04-13 11:28:14.227 28459-28459/com.esmad.pdm.friendlymanager D/image2: gs:// friendlymanager-3b7a2.appspot.com/Photos/LqZ5YSxHQZY7JKta5EGWiL3MXi93.jpg

标签: android firebase firebase-storage


【解决方案1】:

你必须得到这样的下载链接,

 StorageReference storageRef = storage.getReference().child("users").child(FirebaseAuth.getInstance().getCurrentUser().getUid()).child(FirebaseAuth.getInstance().getCurrentUser().getUid());//reach out to your photo file hierarchically as stored  on firebase
            storageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                @Override
                public void onSuccess(Uri uri) {
                    Log.e("URI", uri.toString());
                    Glide.with(SaveUserActivity.this).load(uri).into(profile_image);
                    url = uri.toString();

                }
            });

【讨论】:

  • 我在哪里传递 uri?
  • 我使用滑翔加载图像,毕加索也有使用 Uri 加载图像的方法。像这样 Picasso.with(context).load(uri).into(imageView);
【解决方案2】:

考虑使用Firebase-UI Android library,它使您能够直接从存储引用加载图像。在你的情况下,它看起来像这样

我不确定是否支持 Picasso,但您可以使用 Glide 例如:

mStorageRef = FirebaseStorage.getInstance().getReference();

Glide.with(this /* context */)
    .using(new FirebaseImageLoader())
    .load(mStorageRef + "/Photos/" + userId)
    .error(R.drawable.default)
    .into(imageView);

【讨论】:

  • 看起来不错,但我需要知道图像格式吗?(jpeg,png)?
  • No Glide 会为你处理所有这些花哨的东西,也会缓存
  • 看起来不错,我会测试它,我会尽快给你反馈
  • 什么是 firebaseImageLoader?找不到
  • Firebase-UI Android 库的一部分将 compile 'com.firebaseui:firebase-ui:1.2.0' 添加到您的依赖项并同步项目有关更多详细信息,请访问答案中的链接
【解决方案3】:

在使用 Picasso 或 glide 等从 Firebase 存储中获取图像时,您应该使用 getDownloadUrl()

【讨论】:

    猜你喜欢
    • 2019-04-08
    • 2017-02-02
    • 2021-12-26
    • 2014-12-04
    • 2020-04-22
    • 1970-01-01
    • 2019-06-11
    • 2017-06-01
    • 1970-01-01
    相关资源
    最近更新 更多