Guest User

Untitled

a guest
Aug 28th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. {
  2. FileOpenPicker openPicker = new FileOpenPicker(); //Открываю изображение
  3. openPicker.ViewMode = PickerViewMode.Thumbnail;
  4. openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
  5. openPicker.FileTypeFilter.Add(".jpg");
  6. openPicker.FileTypeFilter.Add(".jpeg");
  7. openPicker.FileTypeFilter.Add(".png");
  8. StorageFile file = await openPicker.PickSingleFileAsync();
  9. if (file != null)
  10. {
  11. if (file != null)
  12. {
  13. using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
  14. {
  15.  
  16. //преобразую поток в байтовый массив
  17. byte[] fileBytes;
  18. using (var Stream = await file.OpenStreamForReadAsync())
  19. {
  20. var binaryReader = new BinaryReader(Stream);
  21. fileBytes = binaryReader.ReadBytes((int)Stream.Length);
  22. }
  23.  
  24. using (var client = new HttpClient())
  25. {
  26.  
  27. var apiUri = new Uri("Некий.Хостинг.php");
  28.  
  29. var imageBinaryContent = new ByteArrayContent(fileBytes);
  30.  
  31. var multipartContent = new MultipartFormDataContent();
  32. multipartContent.Add(imageBinaryContent, "image" );
  33.  
  34. var result = await client.PostAsync(apiUri, multipartContent);
  35. Name.Text = result.Content.ReadAsStringAsync().Result;
  36. }
  37. }
  38. }
  39. }
  40. else
  41. {
  42. Name.Text = "Operation cancelled.";
  43. }
  44. }
Add Comment
Please, Sign In to add comment