Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Error ReasonPhrase: 'Request-URI Too Long', Version: 1.1, cause image convertion to byte

$
0
0

Halo Everyone,
I work on a xamarin forms app, and I need to convert my image to byte and then upload it when InsertMethod call. The conversion result will be one of the parameters in insert method. But when I try to upload the image I got this error:

StatusCode: 414, ReasonPhrase: 'Request-URI Too Long', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:

It cause of the conversion result, in byte format, is too long, Is there another way to convert them the image or to set the maximum URL length?
This is my code for pick the image and converts it. Thank you.
private async void PickPhoto_Clicked(object sender, EventArgs e)
{
try
{
await CrossMedia.Current.Initialize();

            if (!CrossMedia.Current.IsPickPhotoSupported)
            {
                await DisplayAlert("No PickPhoto", ":( No PickPhoto available.", "OK");
                return;
            }

            _mediaFile = await CrossMedia.Current.PickPhotoAsync();

            if (_mediaFile == null)
                return;

            LocalPathLabel.Text = _mediaFile.Path;

            FileImage.Source = ImageSource.FromStream(() =>
            {
                return _mediaFile.GetStream();
            });

            using (var memoryStream = new MemoryStream())
            {
                _mediaFile.GetStream().CopyTo(memoryStream);
                _mediaFile.Dispose();
                imageAsBytes = memoryStream.ToArray();

                var byteArray = memoryStream.ToArray();
                string base64String = Convert.ToBase64String(byteArray);
                fileBytee = base64String;
            }
        }
        catch (Exception a)
        {
            Debug.WriteLine(a.Message);
            Debug.WriteLine("eeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
        }
    }

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>