我正在尝试创建一个表格,用于在Firebase存储中存储图像的引用!图像正在上传并存储在Firebase存储中,但我无法创建表格以在我的数据库中引用它
这是我的代码:
private async 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)
{
//get the logged on user so we know who made the category
var user = FirebaseAuth.Instance.CurrentUser;
//Link the photo in storage to database reference
try
{
var newImageDetails = storageRef.Child("images");
Photo photos = new Photo();
photos.categoryId = newImageDetails.Name;
photos.photoId = newImageDetails.Name;
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);
}
catch (System.Exception e)
{
}
progressDialog.Dismiss();
Toast.MakeText(this, "Successfully uploaded image",
ToastLength.Short).Show();
}
当我使用断点进行测试时,代码表示try catch块中的项为空?
答案 0 :(得分:0)
将图片网址的代码移动到图片引用的成功监听器内的firebaseDB中,因为只有在上传数据之后,成功的firebase才会为您提供网址。
目前获取链接的代码不会等待文件上传,然后获取网址