示例#1
0
        public async Task UploadFile(Windows.Storage.StorageFile Photofile)
        {
            var sourceData = new FileStream(@photoFile.Path, FileMode.Open);
            await sourceData.ReadAsync(new byte[1], 0, 1);

            AzureIoTHub.SendToBlobAsyncStream(photoFile, sourceData).Wait();
        }
示例#2
0
        private async void TakePicture()
        {
            try
            {
                takePhoto.IsEnabled   = false;
                recordVideo.IsEnabled = false;
                captureImage.Source   = null;


                //new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation().Id.ToString()


                //Get Device ID from IOT Hub for File name
                PHOTO_FILE_NAME = "YYC01_"
                                  + DateTime.UtcNow.Year + DateTime.UtcNow.Month + DateTime.UtcNow.Day + DateTime.UtcNow.Hour + DateTime.UtcNow.Minute
                                  + DateTime.UtcNow.Second + ".jpg";


                photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
                    PHOTO_FILE_NAME, CreationCollisionOption.GenerateUniqueName);

                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

                takePhoto.IsEnabled = true;
                status.Text         = "Take Photo succeeded and file saved to: " + photoFile.Path;

                IRandomAccessStream photoStream = await photoFile.OpenReadAsync();

                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(photoStream);
                captureImage.Source = bitmap;
                //---------------------------------------------------------------------------
                status.Text = "Uploading Photo to IOT Hub";

                var reader = new DataReader(photoStream.GetInputStreamAt(0));
                var bytes  = new byte[photoStream.Size];
                await reader.LoadAsync((uint)photoStream.Size);

                reader.ReadBytes(bytes);
                var stream = new MemoryStream(bytes);

                await AzureIoTHub.SendToBlobAsyncStream(photoFile, stream);


                status.Text = "File Uploaded!";
            }



            catch (Exception ex)
            {
                status.Text = ex.Message;
                Cleanup();
            }
            finally
            {
                takePhoto.IsEnabled   = true;
                recordVideo.IsEnabled = true;
            }
        }