From c3bc0d682f6df802e9a865302a1e5d30408d9170 Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Sat, 6 May 2017 21:50:52 +0200 Subject: Added ImgurPhotoUploader. --- .../ApartmentManager/ApartmentManager.csproj | 4 ++ .../Persistency/ImgurPhotoUploader.cs | 48 ++++++++++++++++++++++ .../ApartmentManager/ViewModel/LoginViewModel.cs | 5 +-- 3 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 ApartmentManager/ApartmentManager/Persistency/ImgurPhotoUploader.cs diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj index 89dcb5e..0bf5485 100644 --- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj +++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj @@ -104,6 +104,7 @@ + @@ -220,6 +221,9 @@ + + 4.0.1 + 5.2.3 diff --git a/ApartmentManager/ApartmentManager/Persistency/ImgurPhotoUploader.cs b/ApartmentManager/ApartmentManager/Persistency/ImgurPhotoUploader.cs new file mode 100644 index 0000000..7e9ebf2 --- /dev/null +++ b/ApartmentManager/ApartmentManager/Persistency/ImgurPhotoUploader.cs @@ -0,0 +1,48 @@ +using Imgur.API.Authentication.Impl; +using Imgur.API.Endpoints.Impl; +using Imgur.API.Models; +using System; +using System.IO; +using System.Threading.Tasks; +using Windows.Storage; +using Windows.Storage.Pickers; + +namespace ApartmentManager.Persistency +{ + public static class ImgurPhotoUploader + { + /// + /// Opens file picker, uploads chosen image and returns link to it. + /// + public async static Task UploadPhotoAsync() + { + //Create new file picker + FileOpenPicker fp = new FileOpenPicker() + { + SuggestedStartLocation = PickerLocationId.PicturesLibrary, + ViewMode = PickerViewMode.Thumbnail, + CommitButtonText = "Upload" + }; + fp.FileTypeFilter.Add(".jpg"); + fp.FileTypeFilter.Add(".jpeg"); + fp.FileTypeFilter.Add(".png"); + fp.FileTypeFilter.Add(".gif"); + fp.FileTypeFilter.Add(".apng"); + fp.FileTypeFilter.Add(".tiff"); + fp.FileTypeFilter.Add(".tif"); + fp.FileTypeFilter.Add(".bmp"); + fp.FileTypeFilter.Add(".pdf"); + fp.FileTypeFilter.Add(".xcf"); + fp.FileTypeFilter.Add(".webp"); + + //Get image file with picker + StorageFile file = await fp.PickSingleFileAsync(); + + //Upload to Imgur and return link + var client = new ImgurClient("7b05a61ed8df74f", "ade6f79163e19f92f852bc553bbe399d7d4218fe"); + var endpoint = new ImageEndpoint(client); + IImage image = await endpoint.UploadImageStreamAsync(await file.OpenStreamForReadAsync()); + return image.Link; + } + } +} \ No newline at end of file diff --git a/ApartmentManager/ApartmentManager/ViewModel/LoginViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/LoginViewModel.cs index 9f1d7f7..0290053 100644 --- a/ApartmentManager/ApartmentManager/ViewModel/LoginViewModel.cs +++ b/ApartmentManager/ApartmentManager/ViewModel/LoginViewModel.cs @@ -1,11 +1,8 @@ -using ApartmentManager.Annotations; -using ApartmentManager.Common; +using ApartmentManager.Common; using ApartmentManager.Handler; using ApartmentManager.Model; using ApartmentManager.View; using System; -using System.ComponentModel; -using System.Runtime.CompilerServices; using System.Windows.Input; using Windows.UI.Popups; using Windows.UI.Xaml; -- cgit v1.2.3