byte []上传到mysql blob不包含任何数据

时间:2017-01-11 18:08:47

标签: c# mysql arrays image uwp

我试图将字节数组上传到mysql列类型mediumblob。在上传之后,我看到blob的大小以千字节为单位,但是,当我下载文件并在记事本中查看时...它只是空白空间。

这里是我如何从图像PNG文件中获取字节:

private async void artworkFileBTN_Click(object sender, RoutedEventArgs e)
    {
        FileOpenPicker openPicker = new FileOpenPicker();
        openPicker.ViewMode = PickerViewMode.Thumbnail;
        openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;

        openPicker.FileTypeFilter.Add(".png");
        artworkfile = await openPicker.PickSingleFileAsync();
        if (artworkfile != null)
        {
            artworkSet = true;
            //var stream = await musicfile.OpenAsync(Windows.Storage.FileAccessMode.Read);
            artworkFileBTN.Content = artworkfile.DisplayName;
            var stream = await artworkfile.OpenAsync(FileAccessMode.Read);
            var streamBytes = await artworkfile.OpenStreamForReadAsync();
            var bytes = new byte[(int)streamBytes.Length];
            ArtworkRawData =bytes;

        }
        else
        {
            //  
        }
    }

谁能告诉我为什么我的数组只包含空格?

1 个答案:

答案 0 :(得分:0)

解决。

 byte[] result;
            using (Stream streambytes = await artworkfile.OpenStreamForReadAsync())
            {
                using (var memoryStream = new MemoryStream())
                {

                    streambytes.CopyTo(memoryStream);
                    result = memoryStream.ToArray();
                }
            }


            ArtworkRawData = result;