我无法使用CloudBlockBlob将照片上传到Azure存储
//module level variables
CameraCaptureTask cameraCaptureTask;
Stream _media;
// Constructor
public MainPage()
{
InitializeComponent();
cameraCaptureTask = new CameraCaptureTask();
cameraCaptureTask.Completed += new EventHandler<PhotoResult>(cameraCaptureTask_Completed);
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
cameraCaptureTask.Show();
}
private async void cameraCaptureTask_Completed(object sender, PhotoResult e)
{
_media = e.ChosenPhoto;
ShowPhotoOnScreen();
var todoItem = CreateToDo(e);
await UploadFileToAzureStorage(todoItem);
}
//Works good till here. It will go off and never come back.
private async Task UploadFileToAzureStorage(TodoItem todoItem)
{
Stream _media ;
// Upload the new image as a BLOB from the stream.
CloudBlockBlob blobFromSASCredential = container.GetBlockBlobReference(todoItem.ResourceName);
_photoCache.Position = 0;
await blobFromSASCredential.UploadFromStreamAsync(_media );
}
这将以异步方式启动,永不返回。我有一种感觉,我正在做一些关于流的错误。
我的问题:
类似的代码可以在Azure存储教程中找到,适用于Win8: http://www.windowsazure.com/en-us/develop/mobile/tutorials/upload-images-to-storage-dotnet/
StorageFile _media = null;
// Get the new image as a stream.
using (var fileStream = await _media.OpenStreamForReadAsync())
{
...
// Upload the new image as a BLOB from the stream.
CloudBlockBlob blobFromSASCredential = container.GetBlockBlobReference(todoItem.ResourceName);
await blobFromSASCredential.UploadFromStreamAsync(fileStream.AsInputStream());
}
Win8与WP8示例中的这一主要差异是
如果您需要更多信息,请与我们联系。感谢。