Still trying to deal with the problem of sending images to the hosting. For the most part, I work at random. Here is what stuck in the application:
{ FileOpenPicker openPicker = new FileOpenPicker(); //Открываю изображение openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".jpeg"); openPicker.FileTypeFilter.Add(".png"); StorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { if (file != null) { using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read)) { //преобразую поток в байтовый массив byte[] fileBytes; using (var Stream = await file.OpenStreamForReadAsync()) { var binaryReader = new BinaryReader(Stream); fileBytes = binaryReader.ReadBytes((int)Stream.Length); } using (var client = new HttpClient()) { var apiUri = new Uri("Некий.Хостинг.php"); var imageBinaryContent = new ByteArrayContent(fileBytes); var multipartContent = new MultipartFormDataContent(); multipartContent.Add(imageBinaryContent, "image" ); var result = await client.PostAsync(apiUri, multipartContent); Name.Text = result.Content.ReadAsStringAsync().Result; } } } } else { Name.Text = "Operation cancelled."; } } Code php file on the server:
<?php $base=$_REQUEST['image']; $filename = $_REQUEST['filename']; // Decode Image $binary=base64_decode($base); header('Content-Type: bitmap; charset=utf-8'); $file = fopen("uploads/".$filename, 'wb'); // Create File fwrite($file, $binary); fclose($file); echo 'Image upload complete, Please check your php file directory'; ?>
But the file does not reach the destination ... Help please understand