0

Use to send the base64 image to the server, and sometimes face the problem of exceeding the maximum line length. How it can be avoided?

enter image description here

Code of my POST:

 var values = new Dictionary<string, string>
       {
        { "kod", "111" },
        { "id_user", user.Id },
        { "image", encodedFile },
        { "title", "MyText" },
        { "text", "1234526" }
       };

        var content = new System.Net.Http.FormUrlEncodedContent(values);

        var response = await client.PostAsync("http://MyUri/tape.php", content);

        var responseString = await response.Content.ReadAsStringAsync();

Full code of my request:

private async void Send_File_But(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();

        var stream = await file.OpenStreamForReadAsync();
        var bytes = new byte[(int)stream.Length];
        stream.Read(bytes, 0, (int)stream.Length);

        string encodedFile = Convert.ToBase64String(bytes);



        var values = new Dictionary<string, string>
       {
        { "kod", "111" },
        { "id_user", user.Id },
        { "image", encodedFile },
        { "title", "MyText" },
        { "text", "1234526" }
       };

        var content = new System.Net.Http.FormUrlEncodedContent(values);

        var response = await client.PostAsync("http://MyUri/tape.php", content);

        var responseString = await response.Content.ReadAsStringAsync();


    }
Denisok
  • 109
  • 5
  • What's generating the error? Is your content *actually* being sent in the body of the request, as I'd expect? (If so, I wouldn't expect there to be any limits.) – Jon Skeet Jul 14 '17 at 10:20
  • This error generating when i choose big image. – Denisok Jul 14 '17 at 10:23
  • That doesn't say *what's* generating the error. Is it in PHP, is it on the client side? You mention the query string in your title - are you suggesting this *is* posting to a long URL? – Jon Skeet Jul 14 '17 at 10:35
  • @JonSkeet Clint side. This error appears when "encodedFile" - so long string. – Denisok Jul 14 '17 at 10:38
  • 1
    Possible duplicate of [How to set large string inside HttpContent when using HttpClient?](https://stackoverflow.com/questions/23703735/how-to-set-large-string-inside-httpcontent-when-using-httpclient) – Crowcoder Jul 14 '17 at 11:56
  • 1
    So how does it "appear"? Fundamentally you've not given us information. – Jon Skeet Jul 14 '17 at 12:21

0 Answers0