Please help me figure out how to add an image to the database. By clicking the "TakePhoto_Tapped" button with a plus, I add a photo from the camera to AvataView, but by clicking the "Next" button, I need to save this photo to the database. I think this screenshot will make it clearer. The screenshot corresponds to the code. enter image description here
XAML
`<toolkit:AvatarView HeightRequest="400"
WidthRequest="280"
Background="#F9F9F9"
x:Name="currenPhoto"
ImageSource="{Binding Photoprofile}">
<Grid>
<Image Source="add.png" HeightRequest="26">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="TakePhoto_Tapped"/>
</Image.GestureRecognizers>
</Image>
</Grid>
</toolkit:AvatarView>`
Method for working with the stream:
private async void TakePhoto_Tapped(object sender, EventArgs e)
{
FileResult photo = await MediaPicker.Default.CapturePhotoAsync(new MediaPickerOptions
{
Title = "Select your photo"
});
if (photo != null)
{
var stream = await photo.OpenReadAsync();
currenPhoto.ImageSource = ImageSource.FromStream(() => stream);
}
}
This is my view model:
public partial class VMSteptree : ObservableObject
{
[ObservableProperty]
private byte _photoprofile;
[RelayCommand]
public static void AddAsync()
{
DbMeeto dba = new();
Auchman auchman = new()
{
Photoprofile = new()
};
dba.Auchmans.Add(auchman);
}
}
Command tied to the button:
<Button Text="Далее"
TextColor="White"
FontSize="Body"
CornerRadius="20"
FontAttributes="Bold"
x:Name="Gotostepfor"
Background="#4C25D9"
Clicked="Gotostepfor_Clicked"
Command="{Binding AddAsyncCommand}">
<Button.Triggers>
<EventTrigger Event="">
<aninmbtn:BtnAnimation/>
</EventTrigger>
</Button.Triggers>
</Button>
My expectation: I expect that the image downloaded from the stream will be transferred to the vie model through data binding and then saved to it through the command on the button.
But what's really going on: When the command is executed, no record is created in the database. I want to add that i use Postgres. And I also connected the necessary packages and directives using and the rest of the data is saved as it should, except for the images.