void cameraCaptureTask_Completed(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK) { //MessageBox.Show(e.ChosenPhoto.Length.ToString()); //Code to display the photo on the page in an image control named myImage. System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage(); bmp.SetSource(e.ChosenPhoto); myImage.Source = bmp; myImage.Tap += new EventHandler <GestureEventArgs>(onImageTap); var todoItem = new allimages { username = uname }; InsertTodoItem(todoItem); } }
private async void InsertTodoItem(allimages todoItem) { string errorString = string.Empty; if (imageStream != null) { // Set blob properties of TodoItem. todoItem.ContainerName = "todoitemimages"; todoItem.ResourceName = Guid.NewGuid().ToString() + ".jpg"; } // Send the item to be inserted. When blob properties are set this // generates an SAS in the response. await todoTable.InsertAsync(todoItem); // If we have a returned SAS, then upload the blob. if (!string.IsNullOrEmpty(todoItem.SasQueryString)) { // Get the URI generated that contains the SAS // and extract the storage credentials. StorageCredentials cred = new StorageCredentials(todoItem.SasQueryString); var imageUri = new Uri(todoItem.ImageUri); // Instantiate a Blob store container based on the info in the returned item. CloudBlobContainer container = new CloudBlobContainer( new Uri(string.Format("https://{0}/{1}", imageUri.Host, todoItem.ContainerName)), cred); // Upload the new image as a BLOB from the stream. CloudBlockBlob blobFromSASCredential = container.GetBlockBlobReference(todoItem.ResourceName); await blobFromSASCredential.UploadFromStreamAsync(imageStream); // When you request an SAS at the container-level instead of the blob-level, // you are able to upload multiple streams using the same container credentials. imageStream = null; } // Add the new item to the collection. items.Add(todoItem); }