Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin 将文件上载到rest wep api c#_Xamarin_Xamarin.forms - Fatal编程技术网

Xamarin 将文件上载到rest wep api c#

Xamarin 将文件上载到rest wep api c#,xamarin,xamarin.forms,Xamarin,Xamarin.forms,您好,我尝试从我的xamarin forms应用程序将图像发送到Web api,并将其保存在数据库中,但我在转换为base 64时遇到问题 我使用插件来选择图像,并尝试将其转换为image base 64,但它没有给我corect字符串image base 64 _aktFile = await CrossMedia.Current.PickPhotoAsync(); if (_aktFile == null) return;

您好,我尝试从我的xamarin forms应用程序将图像发送到Web api,并将其保存在数据库中,但我在转换为base 64时遇到问题 我使用插件来选择图像,并尝试将其转换为image base 64,但它没有给我corect字符串image base 64

    _aktFile = await CrossMedia.Current.PickPhotoAsync();

            if (_aktFile == null)
                return;
            ImageSource = ImageSource.FromStream(() =>
                {
                    ImageStream = _aktFile.GetStream();
                    ImageMessageByteArray = new byte[_ImageStream.Length];
                    ImageStream.Read(_ImageMessageByteArray, 0, (int)_ImageStream.Length);
                    ImageMessageBase64 = System.Convert.ToBase64String(_ImageMessageByteArray);
                    return _aktFile.GetStream();
                    
                });

“没有给我正确的字符串”-你如何确定它不正确?我如何使用它以及我应该如何使用它?这并没有回答我的问题,也没有真正为你的原始帖子添加任何有用的信息。
_aktFile = await CrossMedia.Current.PickPhotoAsync();

if (_aktFile == null)
 return;
else
{
 string Base64String = ConvertStreamToBase64(_aktFile);
}

private string ConvertStreamToBase64(Stream stream)
        {
            if (stream != null)
            {
                byte[] bytes;
                using (var memoryStream = new MemoryStream())
                {
                    stream.Seek(0, SeekOrigin.Begin);
                    stream.CopyTo(memoryStream);
                    bytes = memoryStream.ToArray();
                }
                base64selectedImage = Convert.ToBase64String(bytes);
                stream.Seek(0, SeekOrigin.Begin);
            }
            return base64selectedImage;
        }