POS-21 Dodano możliwość wysyłania zdjęcia do serwera.
This commit is contained in:
parent
b9f6739a55
commit
7687c54609
@ -12,6 +12,7 @@ using System.Collections.Generic;
|
|||||||
using System.Security;
|
using System.Security;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Klient.Droid
|
namespace Klient.Droid
|
||||||
{
|
{
|
||||||
@ -20,6 +21,7 @@ namespace Klient.Droid
|
|||||||
{
|
{
|
||||||
public static int PickImageId = 1000;
|
public static int PickImageId = 1000;
|
||||||
private static readonly HttpClient client = new HttpClient();
|
private static readonly HttpClient client = new HttpClient();
|
||||||
|
public static Android.Content.Intent photo;
|
||||||
|
|
||||||
protected override void OnCreate(Bundle savedInstanceState)
|
protected override void OnCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
@ -136,8 +138,28 @@ namespace Klient.Droid
|
|||||||
{
|
{
|
||||||
SetContentView(Resource.Layout.ekranPoZdjeciu);
|
SetContentView(Resource.Layout.ekranPoZdjeciu);
|
||||||
Android.Net.Uri uri = data.Data;
|
Android.Net.Uri uri = data.Data;
|
||||||
|
photo = data;
|
||||||
FindViewById<ImageView>(Resource.Id.Preview).SetImageURI(uri);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user