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?
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();
}