我已經使用WCF REST服務創建了Azure Cloud Service。我正在開發blob的本地存儲開發。目前,我已經能夠將容器中的文件從計算機上傳到Listbox1中。現在,我需要從我的Listbox1中選擇一個項目(blob)並下載所選項目。 這裏是我的代碼:在JavaScript中下載Blob
public void DownloadBlob(AzureDataContract download) {
// Connect to the storage account's blob endpoint
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("AzureStorageConnectionString"));
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Create the blob storage container
CloudBlobContainer container = blobClient.GetContainerReference(download.ContainerName);
container.CreateIfNotExists();
// Create the blob in the container
CloudBlockBlob blob = container.GetBlockBlobReference("test");
using (var fileStream = System.IO.File.OpenWrite(download.FilePath))
{
blob.DownloadToStream(fileStream);
}
}
然後我試圖調用使用JQuery和Ajax我的方法如下:
$('#btnDownload').click(function() {
var download = {
"ContainerName": $("#listContainer").val(),
"FilePath": $("#listBlob option:selected").val()
};
$.ajax({
type: "POST",
url: "http://localhost:49416/AzureService.svc/DownloadBlob",
data: JSON.stringify(download),
contentType: "application/json; charset=utf-8",
dataType: "json",
processData: true,
success: function(data) {
alert("downloading");
},
error: function(data) {
alert("error");
}
});
});
有沒有你得到的錯誤? –
是的,我有這個問題: mscorlib中發生了類型'System.UnauthorizedAccessException'的異常。但沒有在用戶代碼中處理 其他信息:訪問路徑'C:\'被拒絕 我已經創建了一個輸入,我在其中設置我的路徑 – Huby03