English 中文(简体)
accessing a blob ; without using a webrole?
原标题:

I wanted to knw if there is way we can upload /download a blob; add remove view metadata without using a webrole ? If my application has a lot of gui, shud there be multiple webroles ? everywhere I see webrole s file default.aspx.cs has everything to do with the blob based on a event ; which is perfectly fine, but what if my gui is more complicated ?

最佳回答

Blobs are accessible via REST calls, so you can actually manipulate blobs with a local desktop app if you wish, even written in PHP or Java.

As for webroles: each role is simply a virtual machine running on some server somewhere. Web roles are just like worker roles, with the addition of IIS. If you have a website, you can put the entire website in a single webrole. If you need to scale it to handle more users, you could create more than one "instance" of that webrole - and then all of your website s requests get sent to the various instances, each running the same code. (yes, you could have multiple webroles for a given app - this might be practical depending on your site s complexity, or if you have a completely different UI for administrators vs visitors).

问题回答

You don t need to use a web role to access Azure Storage (Blob or otherwise). You can use a worker role, or you can even access it from a Windows Forms app running on a desktop, or a web/service app which isn t running on Azure.

See the Azure SDK s StorageClient documentation for info on how to access Azure Storage - it s pretty easy.

You don t need Azure project or other roles to use blob. If you want to use Azure client in .Net project, you can add your config to app settings section and reference it. Azure client is a wrapper to rest calls. They have some request signing steps which make the calls difficult to implement with simple webrequests.

 <add key="AzureBlobStorage" value="AccountName=youraccountname;AccountKey=YOURKEYeZgfgdfg==;DefaultEndpointsProtocol=https"/>

You can get the blob client:

 public CloudBlobClient GetBlobClient()
    {
        var accountBlob = ConfigurationManager.AppSettings["AzureBlobStorage"];

        var account = CloudStorageAccount.Parse(accountBlob.ToString());


        return account.CreateCloudBlobClient();

    }


public CloudBlob GetBlob(BlobItem blobItem)
        {
            var client = GetBlobClient();
            var cloudBlobContainer = client.GetContainerReference(blobItem.ContainerReference);
            return cloudBlobContainer.GetBlobReference(blobItem.FileName);
        }

BlobItem is just a wrapper. Basically, you need folder name and filename to access a blob.

 public class BlobItem
{
    [Required]
    [Display(Name = "Container")]
    public string ContainerReference { get; set; }
    [Required]
    [Display(Name = "File name")]
    public string FileName { get; set; }

    [Required]
    [UIHint("MultilineText")]
    public string Content { get; set; }

    /// <summary>
    /// to use in stream mode
    /// </summary>
    public Stream Stream { get; set; }
}




相关问题
Windows Azure WorkerRole response

I am working on an Azure demo to run Powershell in a worker role. In my web role I add the name of the Powershell script which is to be run to a CloudQueue object. I can print the script output to ...

Windows Azure WebRole stuck in a deployment loop

I ve been struggling with this one for a couple of days now. My current Windows Azure WebRole is stuck in a loop where the status keeps changing between Initializing, Busy, Stopping and Stopped. It ...

Getting a token for Windows Azure

We are looking at Windows Azure, but getting a token appears to be hard now, at least that s what I m seeing in web searches. Anyone tried it or know how to accelerate that process? Any idea how long ...

Developing Azure .Net 4.0 Applications

Presently .Net 4.0 is not supported on Azure. This thread indicates that you will not be able to use .Net 4.0 with VS 2010 until it is supported in the cloud. http://social.msdn.microsoft.com I d ...

.NET 4.0 on Windows Azure?

My google-fu is failing me on this one. As a possible solution to Unit Testing .NET 3.5 projects using MStest in VS2010 (but I ve put this in a seperate question because it s kind of unrelated): Is ...

热门标签