0

I have created an Azure Cloud Service with a WCF REST service. I am working on the local storage development with blobs. At this time, I've been able to upload files from my computer in containers and list them as well in a Listbox1. Now, i need to select an item(blob) from my Listbox1 and download the selected item. Here's my code:

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); } } 

Then i am trying to call my method using JQuery and Ajax as follow:

$('#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"); } }); });

2
  • Is there any error you're getting? Commented Feb 27, 2016 at 15:54
  • Yes, i have this problem: An exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll but was not handled in user code Additional information: Access to the path 'C:\' is denied. I have create an input where i set my path Commented Feb 27, 2016 at 19:48

2 Answers 2

1

At this moment your DownloadBlob function is not returning anything. It is a void function. So your client will never receive the blob. What it is doing at the moment is writing the blob to a file on the server disk (download.FilePath). If you want to download anything in your rest call, you should return the file to the client.

Sign up to request clarification or add additional context in comments.

Comments

0

Your code looks fine. After running, the blob file should have been downloaded to your 'FilePath' location. 'System.UnauthorizedAccessException' normally happened when you have no right to delete/create a file under a folder. I think you can check if you have write access to "FilePath' position.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.