POS-21 Dodano możliwość wysyłania zdjęcia do serwera.

This commit is contained in:
Wojciech Przybyła 2020-12-14 00:17:38 +01:00
parent b9f6739a55
commit 7687c54609

View File

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