2013-02-27 257 views
0

Azure SDK在Windows 8 APP上無法使用。將Windows 8的照片上傳到Azure Blob存儲

如何從Windows 8應用程序上傳照片到Azure Blob存儲?

我需要工作代碼示例。

+0

假設您使用的是Windows 8 Azure SDK? http://blogs.msdn.com/b/windowsazurestorage/archive/2012/11/05/windows-azure-storage-client-library-for-windows-runtime.aspx – 2013-02-27 13:55:18

+0

嘗試添加使用Microsoft.WindowsAzure時出現錯誤.Storage.Blob參考... – 2013-02-27 14:04:14

回答

2

您不需要Windows Azure SDK將照片從Windows 8應用程序上傳到Blob存儲。 HttpClient的也沒關係:

using (var client = new HttpClient()) 
{ 
    CameraCaptureUI cameraCapture = new CameraCaptureUI(); 
    StorageFile media = await cameraCapture.CaptureFileAsync(CameraCaptureUIMode.PhotoOrVideo); 
    using (var fileStream = await media.OpenStreamForReadAsync()) 
    { 
      var content = new StreamContent(fileStream); 
      content.Headers.Add("Content-Type", media.ContentType); 
      content.Headers.Add("x-ms-blob-type", "BlockBlob"); 

      var uploadResponse = await client.PutAsync(
             new Uri(blobUriWithSAS), image); 
    } 
} 

你需要做的唯一的事情就是與簽名的接入簽名獲得的URL BLOB在一起。 Nick Harris explains你如何使用移動服務來做到這一點。

+0

謝謝,但是我把新的URI()放在什麼地方? – 2013-02-27 14:35:34

+1

我收到錯誤:請求URI中指定的其中一個查詢參數的值無效 – 2013-02-27 14:41:23