1

I have created an application using "window azure cloud service" where i m uplodaing/downloading azure blob files like this

Upload Code

public ActionResult UploadImage_post(HttpPostedFileBase fileBase)
    {
        if (fileBase.ContentLength > 0)
        {
            Microsoft.WindowsAzure.StorageClient.CloudBlobContainer blobContainer =
                _myBlobStorageService.GetCloudBlobContainer();

            Microsoft.WindowsAzure.StorageClient.CloudBlob blob =
                blobContainer.GetBlobReference(fileBase.FileName);

            blob.UploadFromStream(fileBase.InputStream);
        }
        return RedirectToAction("UploadImage");
    }

Download Code

Microsoft.WindowsAzure.StorageClient.CloudBlobContainer blobContainer =
         _myBlobStorageService.GetCloudBlobContainer();

        Microsoft.WindowsAzure.StorageClient.CloudBlob blob =
            blobContainer.GetBlobReference(filename);

return Redirect(blobContainer.GetBlobReference(filename).Uri.AbsoluteUri);

Here is my view

@foreach (var item in Model)
{
        <img src="@item" width="200" height="100" />
        <a href="/Blob/Download?filename=@item">Download</a> 
}

Situation is, i m setting a Download limit for Users, so i need to get File size before downloading so that i can check if "Download Limit" is reached or not.

enter image description here

you can see here that there is a "Data Left" field. Before downloading another file i need to check if

    Downloaded File size > Data Left

then it should not download.

Please suggest

Anil D
  • 1,989
  • 6
  • 29
  • 60

1 Answers1

1

You would have to check the size of the blob before deciding if there is enough bandwidth for the download.

Microsoft.WindowsAzure.StorageClient.CloudBlob blob =
            blobContainer.GetBlobReference(filename);

blob.FetchAttributes();

var blobsize = blob.Properties.Length; // this is in bytes
// is size less than bandwidth left. etc

Spoiler : this will actually query the blob, so I would assume a transaction charge every hit not to mention the increased latency of having to wait the request out; I would suggest you record the filesize on upload and save that off to your db or other persistent storage.

cillierscharl
  • 7,043
  • 3
  • 29
  • 47
  • Hey @f0x, will you please provide some suggestions on http://stackoverflow.com/questions/23744500/downloading-encrypted-file-from-window-azure-storage – Anil D May 28 '14 at 06:37