c# - 我无法使用图像 url 在应用程序中显示来自 firebase 存储的图像
问题描述
我想显示已成功存储到 Firebase 存储中的图像。我让用户从图库中选择图像并将其保存在数据库中。然后我将 URL 链接保存在实时数据库中,我认为我可以绑定到 image.source 但这不起作用。我还尝试将链接从 firebase 控制台直接复制到不起作用的 XAML 中。我还尝试将图像下载到手机上(下面的代码),但这不起作用。我在任何地方都找不到任何教程来为 Xamarin 表单显示来自 firebase 的图像。我有点卡在这里。
public void LoadImages(string imgurl)
{
var webClient = new WebClient();
byte[] imgBytes = webClient.DownloadData(imgurl);
//string img = Convert.ToBase64String(imgBytes);
petimage.Source = ImageSource.FromStream(() => new MemoryStream(imgBytes));
}
protected override void OnAppearing()
{
base.OnAppearing();
RetrivePetInfo();
}
private async void RetrivePetInfo()
{
var pet = await firebaseHelper.GetPet(PetName);
if (pet != null)
{
if(pet.imageUrl!=null)
{
LoadImages(pet.imageUrl);
}
}
}
解决方案
我已经看过其他问题了。我尝试了以下代码:
public async Task<ImageSource> LoadImages(string fileName)
{
var webClient = new WebClient();
var stroageImage = await new FirebaseStorage("zain*******.appspot.com")
.Child("PetProfileImages")
.Child(fileName)
.GetDownloadUrlAsync();
string imgurl = stroageImage;
byte[] imgBytes = webClient.DownloadData(imgurl);
//string img = Convert.ToBase64String(imgBytes);
img = ImageSource.FromStream(() => new MemoryStream(imgBytes));
return img;
}
但是我收到一个新的firebase错误:(Firebase.Storage.FirebaseStorageException:'处理请求时发生异常。网址:https ://firebasestorage.googleapis.com/v0/b/*********.appspot .com/o/PetProfileImages%2F 响应:
{
“错误”:{“代码”:404,“消息”:“未找到。无法获取对象”,“状态”:“GET_OBJECT”}}
推荐阅读
- android - 我正在尝试统一构建我的 android 游戏,但他们向我展示了一个问题“无法合并 android 清单”
- python - 将 python 项目部署到 PYPI 时隐藏 API 密钥
- reactjs - 如何在 Highcharts 的图表中呈现具有 x 和 y 值的对象数组“webdata”?
- php - 如何在不替换旧文本的情况下将文本添加到文本区域
- java - 错误程序类型已存在:程序类型已存在:添加新库时的 androidx.recyclerview.widget.AdapterHelper$Callback
- excel - 用文本和图像从 Excel 填充 Word 文档,图像部分需要帮助
- azure - AKS 上的身份服务器
- c++ - 使用点云库 ICP 进行 2D 点匹配
- c# - 从 JObject 中删除双花括号
- docker - 为什么默认启用docker暴露?