所以我需要将图像以及其他一些字符串(例如名称)上传到我的 Mysql 数据库中...我能够将名称添加到 Mysql DB 中,但我无法对图像执行此操作。我将图像转换为字节 [],现在我被卡住了..这是我使用的代码
private Stream stream = new MemoryStream();
private CancellationTokenSource cts;
public MainPage()
{
this.InitializeComponent();
}
private async void buttonUpload_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker open = new FileOpenPicker();
open.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
open.ViewMode = PickerViewMode.Thumbnail;
// Filter to include a sample subset of file types
open.FileTypeFilter.Clear();
open.FileTypeFilter.Add(".bmp");
open.FileTypeFilter.Add(".png");
open.FileTypeFilter.Add(".jpeg");
open.FileTypeFilter.Add(".jpg");
// Open a stream for the selected file
StorageFile file = await open.PickSingleFileAsync();
// Ensure a file was selected
if (file != null)
{
// …Run Code Online (Sandbox Code Playgroud)