Added fileupload
This commit is contained in:
@@ -10,6 +10,9 @@ using Newtonsoft.Json;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Windows.Foundation;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using Windows.Storage;
|
||||
|
||||
namespace YJMPD_UWP.Model
|
||||
{
|
||||
@@ -82,7 +85,7 @@ namespace YJMPD_UWP.Model
|
||||
//din.UnicodeEncoding = UnicodeEncoding.Utf8;
|
||||
//din.ByteOrder = ByteOrder.LittleEndian;
|
||||
|
||||
dout.UnicodeEncoding = UnicodeEncoding.Utf8;
|
||||
dout.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8;
|
||||
dout.ByteOrder = ByteOrder.LittleEndian;
|
||||
|
||||
UpdateNetworkStatus(NetworkStatus.CONNECTED);
|
||||
@@ -150,5 +153,6 @@ namespace YJMPD_UWP.Model
|
||||
App.Api.HandleMessage(o);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Graphics.Imaging;
|
||||
using Windows.Media.Capture;
|
||||
@@ -60,7 +63,44 @@ namespace YJMPD_UWP.Model
|
||||
SoftwareBitmapSource bitmapSource = new SoftwareBitmapSource();
|
||||
await bitmapSource.SetBitmapAsync(softwareBitmapBGR8);
|
||||
|
||||
await UploadImage(stream.AsStream());
|
||||
|
||||
UpdatePhotoTaken(bitmapSource);
|
||||
}
|
||||
|
||||
public async Task<string> UploadImage(Stream file)
|
||||
{
|
||||
string url = "http://jancokock.me/f/?plain";
|
||||
MultipartFormDataContent postdata = new MultipartFormDataContent();
|
||||
postdata.Add(new ByteArrayContent(ReadFully(file)), "file", "capture.png");
|
||||
using (HttpClient hc = new HttpClient())
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await hc.PostAsync(url, postdata);
|
||||
response.EnsureSuccessStatusCode();
|
||||
Debug.WriteLine(await response.Content.ReadAsStringAsync());
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new IOException("Network error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] ReadFully(Stream input)
|
||||
{
|
||||
byte[] buffer = new byte[16 * 1024];
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
int read;
|
||||
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
ms.Write(buffer, 0, read);
|
||||
}
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +168,9 @@
|
||||
<Content Include="Assets\Square150x150Logo.scale-200.png" />
|
||||
<Content Include="Assets\Square44x44Logo.scale-200.png" />
|
||||
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
|
||||
<Content Include="Assets\StoreLogo.png" />
|
||||
<Content Include="Assets\StoreLogo.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user