使用FirebaseUI将图像从Cloud Firestore直接下载到imageView

时间:2019-07-17 15:48:07

标签: android firebase-storage android-glide

我是Firebase的新手,我刚刚完成了有关实时数据库和云Firestore的设置和文档。我正在尝试测试文档的一部分,您可以在其中使用FirebaseUI将图像直接下载到ImageView(reference)中。这是他们的代码:

// Reference to an image file in Cloud Storage
StorageReference storageReference = FirebaseStorage.getInstance().getReference();

// ImageView in your Activity
ImageView imageView = findViewById(R.id.imageView);

// Download directly from StorageReference using Glide
// (See MyAppGlideModule for Loader registration)
GlideApp.with(this /* context */)
        .load(storageReference)
        .into(imageView);FirebaseUIActivity.java

这是我的代码:

FirebaseStorage storage = FirebaseStorage.getInstance();

StorageReference iconRef = storage.getReferenceFromUrl("https://firebasestorage.googleapis.com/rest_of_the_link");

// ImageView in your Activity
ImageView imageView = findViewById(R.id.iconImageView);

// Download directly from StorageReference using Glide
// (See MyAppGlideModule for Loader registration)
Glide.with(this /* context */)
        .load(iconRef)
        .into(imageView);

}

我在firestore中有一个.webp图像,我使用StorageReference iconRef对其进行了引用,然后尝试将其加载到ImageView中。可悲的是,那没有用。我在这里想念什么?另外,是否因为找不到GlideApp部分而将Glide替换为const data = { firstName: name, surname: surname, email: email, password: pass1, roles: roles }; state.search.method("POST", "users", JSON.stringify(data)); method(type_, url_, data_){ $.ajax({ url: proxy + url_, type: type_, contentType: "x-www-form-urlencoded", dataType: "json", headers: { 'Authorization': 'bearer ' + localStorage.access_token }, data: data_, success: function(result){ alert("OK METHOD"); }, error(XMLHttpRequest, textStatus, errorThrown){ alert('Error: ' + errorThrown + ", " + textStatus); console.log(XMLHttpRequest.status + ' ' + XMLHttpRequest.statusText); } }); }

1 个答案:

答案 0 :(得分:0)

尝试创建一个名为GlideApp的文件(或任何您想要的文件):

@GlideModule class GlideApp extends AppGlideModule { }

,然后使用GlideApp.with(this /* context */) .load(iconRef) .into(imageView);