从WP8将照片上传到Azure存储

时间:2013-10-02 08:59:22

标签: c# azure windows-phone-8

我无法使用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 );
    }

这将以异步方式启动,永不返回。我有一种感觉,我正在做一些关于流的错误。

我的问题:

  1. 我应该如何处理流?
  2. 我没有看到完成的活动 在UploadFromStreamAsync上,是否有一种聪明的捕获方式 我应该使用OnCompleted还是其他方法?
  3. 类似的代码可以在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示例中的这一主要差异是

    1. 在WP8中捕获照片StorageFile(Win8)和Stream。
    2. AsInputStream在WP8中似乎无效
    3. 如果您需要更多信息,请与我们联系。感谢。

0 个答案:

没有答案