【发布时间】:2018-02-04 06:53:24
【问题描述】:
我正在尝试创建一个将图像引用存储在 Firebase 存储中的表!图片正在上传并存储在 Firebase Storage 中,但我无法创建表以在我的数据库中引用它
这是我的代码:
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 块中的项目为空?
【问题讨论】:
标签: c# firebase xamarin firebase-realtime-database firebase-storage