C# 使用身份验证ID在Firebase中存储图像-Xamarin
我可以将图像保存到firebase存储中,但在存储中,没有任何信息可以告诉我上传照片的用户的id。在我的应用程序中,用户可以为博客上传照片,而且就这一点而言,每一张更新的照片都应该有用户的id和博客的密钥。因此,我可以很容易地为每个博客分别获取图像。我怎样才能做到这一点 这就是我保存图像的方式C# 使用身份验证ID在Firebase中存储图像-Xamarin,c#,android,firebase,xamarin.android,firebase-storage,C#,Android,Firebase,Xamarin.android,Firebase Storage,我可以将图像保存到firebase存储中,但在存储中,没有任何信息可以告诉我上传照片的用户的id。在我的应用程序中,用户可以为博客上传照片,而且就这一点而言,每一张更新的照片都应该有用户的id和博客的密钥。因此,我可以很容易地为每个博客分别获取图像。我怎样才能做到这一点 这就是我保存图像的方式 public void OnClick(View v) { Intent intent = new Intent(); intent.Se
public void OnClick(View v)
{
Intent intent = new Intent();
intent.SetType("image/*");
intent.SetAction(Intent.ActionPick);
StartActivityForResult(Intent.CreateChooser(intent, "Select Image"), PICK_IMAGE_REQUEST);
}
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
try{
Bitmap bitmap = MediaStore.Images.Media.GetBitmap(this.ContentResolver, data.Data);
using (MemoryStream stream = new MemoryStream())
{
bitmap.Compress(Bitmap.CompressFormat.Jpeg,100,stream);
byte[] array = stream.ToArray();
imageViewDrop.SetImageBitmap(bitmap);
}
if(data.Data != null){
pd = new ProgressDialog(this);
pd.SetTitle("Uploading");
pd.Show();
StorageReference images = storageRef.Child("images");
images.PutFile(data.Data).AddOnSuccessListener(this);
images.PutFile(data.Data).AddOnProgressListener(this);
}
else {
}
imageViewDrop.SetImageBitmap(bitmap);
}
catch (Java.Lang.Exception e){
}
}
public void OnSuccess(Java.Lang.Object result)
{
pd.Dismiss();
}
public void OnProgress(Java.Lang.Object snapshot)
{
}
您可以使用用户的
Uid
在存储器中为每个用户创建引用
我假设您的storageRef
位于StorageReference images=storageRef.Child(“images”)
表示FirebaseStorage.Instance.Reference
,然后首先按如下方式检查当前用户:
FirebaseAuth mAuth = FirebaseAuth.Instance;
FirebaseUser user = mAuth.CurrentUser;
如果用户为null,当然我们需要进行身份验证,但如果不是null,则首先创建一个用户引用,然后在此引用下创建您的“图像”或“博客”等等。。。例如:
FirebaseStorage storage = FirebaseStorage.Instance;
//create child reference
StorageReference storageRef = storage.Reference;
var userRef = storageRef.Child(user.Uid);
var imageRef = userRef.Child("images");