/// <summary> /// Method to upload the image with the service /// </summary> /// <param name="image"></param> /// <returns></returns> private async void MakePostRequest(uploadIMG image) { #if DEBUG Debug.WriteLine(image.filename + " has started"); #endif //Try to upload the image try { image.uploadstatus = await client.UploadPhotoAsync(image.filename, image.imageStream, userId); } catch (Exception e) { //Upload has failed, we want to know why image.uploadstatus = e.Message; } #if DEBUG Debug.WriteLine(image.filename + " is done"); #endif }
/// <summary> /// Method for the open button, to open filepicker /// </summary> /// <param name="sender">Button object</param> /// <param name="e"></param> private async void openBtn_Click(object sender, RoutedEventArgs e) { //Create a filepicker FileOpenPicker openPicker = new FileOpenPicker(); //Add settings to the filepicker openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".png"); //We have to wait until the user has decided which images he wants to upload, if any IReadOnlyList <StorageFile> filelist = await openPicker.PickMultipleFilesAsync(); foreach (var file in filelist) { var randomAccessStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); Stream managedStream = randomAccessStream.AsStream(); var newImage = new uploadIMG(); //Check if the image size is less than 1 MB if (managedStream.Length > 1048576) { newImage.uploadstatus = "Image exceeds sizelimit"; } else { newImage.imageStream = ReadFully(managedStream); newImage.uploadstatus = "Added to queue"; } newImage.filename = file.Name; uploadImages.Add(newImage); } }