From 7687c54609203bac64a5b0b163711c70ef29da34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Przyby=C5=82a?= Date: Mon, 14 Dec 2020 00:17:38 +0100 Subject: [PATCH] =?UTF-8?q?POS-21=20Dodano=20mo=C5=BCliwo=C5=9B=C4=87=20wy?= =?UTF-8?q?sy=C5=82ania=20zdj=C4=99cia=20do=20serwera.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Klient/Klient/Klient.Android/MainActivity.cs | 24 +++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Klient/Klient/Klient.Android/MainActivity.cs b/Klient/Klient/Klient.Android/MainActivity.cs index fdc7931..849ba9e 100644 --- a/Klient/Klient/Klient.Android/MainActivity.cs +++ b/Klient/Klient/Klient.Android/MainActivity.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Security; using System.Net; using System.Linq; +using System.IO; namespace Klient.Droid { @@ -20,6 +21,7 @@ namespace Klient.Droid { public static int PickImageId = 1000; private static readonly HttpClient client = new HttpClient(); + public static Android.Content.Intent photo; protected override void OnCreate(Bundle savedInstanceState) { @@ -136,8 +138,28 @@ namespace Klient.Droid { SetContentView(Resource.Layout.ekranPoZdjeciu); Android.Net.Uri uri = data.Data; + photo = data; FindViewById(Resource.Id.Preview).SetImageURI(uri); - + } + + [Java.Interop.Export("SendPhoto")] + async public void UploadPhoto(View v) + { + using(var imageStream = ContentResolver.OpenInputStream(photo.Data)) + using(var stramContent = new StreamContent(imageStream)) + using(var byteArrayContent = new ByteArrayContent(await stramContent.ReadAsByteArrayAsync())) + using(var formDataContent = new MultipartFormDataContent()) + { + formDataContent.Add(byteArrayContent, "file", Guid.NewGuid() + ".jpg"); + foreach (var content in formDataContent) + { + content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(ContentResolver.GetType(photo.Data)); + break; + } + var response = await client.PostAsync("http://10.0.2.2:5001/api/Image/Process", formDataContent); + } + } + } } \ No newline at end of file