从 Firebase 存储 Xamarin 获取图像下载 url [英] Get image download url from firebase storage Xamarin
问题描述
我正在尝试从上传到 firebase 存储的照片中获取图像 url,以便我可以将对该图像的引用存储在另一个表中,这将允许我能够在整个应用程序的其他地方显示该图像.
Im trying to get the image url from a photo I uploaded to firebase storage so I can store the reference to the image in another table which will allow me to be able to display the image elsewhere throughout the app.
我现在有
private void UploadPhoto()
{
if (filePAth != null)
{
progressDialog = new ProgressDialog(this);
progressDialog.SetTitle("Uploading...");
progressDialog.Window.SetType(Android.Views.WindowManagerTypes.SystemAlert);
progressDialog.Show();
var images = storageRef.Child("images/" + Guid.NewGuid().ToString());
images.PutFile(filePAth)
.AddOnProgressListener(this)
.AddOnSuccessListener(this)
.AddOnFailureListener(this);
}
}
public async void OnSuccess(Java.Lang.Object result)
{
try
{
var newImageDetails = storageRef.Child("images" + "/" + filePAth);
Photo photos = new Photo();
photos.categoryName = spinner.SelectedItem.ToString();
photos.photoId = newImageDetails.Name;
photos.ImageUrl = storageRef.DownloadUrl.ToString();
photos.tagName = addTag.Text;
if (user != null)
{
var uid = user.Uid;
//set the users id to the category
photos.uid = uid;
}
var firebase = new FirebaseClient(FirebaseURL);
var item = await firebase.Child("photos").PostAsync(photos);
}
}
storageref.DownloadUrl 没有给我正确的网址这就是我要找的
The storageref.DownloadUrl does not give me the correct url This is what I am looking for
推荐答案
我在调试模式下找到了解决方案
I got a solution in debugging mode
我看到了 downloadurl 的属性并找到了 Scheme 和 SchemeSpecificPart
i saw the downloadurl's properties and found the Scheme and SchemeSpecificPart
方案 = https"
Scheme = "https"
SchemeSpecificPart = "//firebasestorage.googleapis.com/v0/b/maplog-e4ba5.appspot.com/o/-L0AMbihF23YKxsL1uss?alt=media&token=5c7ccef1-c857-4982-a2fa280ff-a2888所以这是我的代码:
SchemeSpecificPart = "//firebasestorage.googleapis.com/v0/b/maplog-e4ba5.appspot.com/o/-L0AMbihF23YKxsL1uss?alt=media&token=5c7ccef1-c857-4982-a288-fded2f0ff1aa" so here is my code:
void IOnSuccessListener.OnSuccess(Java.Lang.Object result)
{
var snapShot = (UploadTask.TaskSnapshot)result;
string imgUrl = snapShot.DownloadUrl.Scheme
+ ":"
+ snapShot.DownloadUrl.SchemeSpecificPart;
}
它有效!我一直在寻找解决方案:((但我终于自己找到了XD
and it works! i was looking for the solution :(( but i finally found it myself XD
这篇关于从 Firebase 存储 Xamarin 获取图像下载 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!