Using blobs from Windows Azure, we can store any type of content (from text file to images or videos). We can look at blobs like a hard disk partition where we can store any type of data.
By default a blob is accessed based on a storage connection string. A consumer will be able to access a specific blob from the storage account based on his credentials. But there are cased when you don’t want to let a user for an unlimited type to have access to your storage account.
For this cased the Shared Access Signature. This feature from Windows Azure permits us to give access to someone for a limited type. Based on the link that is generated by Shared Access Signature the consumer will be able to use the given blob.
Basically, the Shared Access Signature is a URL that gives the user access to a specific resource. In general these resources can be a container, a blob, table or queues. In this blog post we will talk about blobs and containers.
The administrator that create the Shared Access Signature have the possibility to specify the period of time when the user have access to the resource and also what operations can be made on it. The old version of Shared Access Signature supported the following operations:
In the next example we will see how we can create a Shared Access Signature. First of all we need to create a blob:
After we have an instance to the blob, we can create a Shared Access Signature.
Tutorials about Shared Access Signature:
By default a blob is accessed based on a storage connection string. A consumer will be able to access a specific blob from the storage account based on his credentials. But there are cased when you don’t want to let a user for an unlimited type to have access to your storage account.
For this cased the Shared Access Signature. This feature from Windows Azure permits us to give access to someone for a limited type. Based on the link that is generated by Shared Access Signature the consumer will be able to use the given blob.
Basically, the Shared Access Signature is a URL that gives the user access to a specific resource. In general these resources can be a container, a blob, table or queues. In this blog post we will talk about blobs and containers.
The administrator that create the Shared Access Signature have the possibility to specify the period of time when the user have access to the resource and also what operations can be made on it. The old version of Shared Access Signature supported the following operations:
- Create blob
- Read/write per blog, page or container
- Delete blob
- Create snapshot
In the next example we will see how we can create a Shared Access Signature. First of all we need to create a blob:
var myContainer = myAccount.CreateCloudBlobClient()
.GetContainerReference(“myContainer”);
// Create the container if don’t exist.
myContainer.CreateIfNotExist();
Var myBlob = container
.GetBlobReference(“firstBlob.txt”);
myBlob.Properties.ContentType = “text/plain”;
myBlob.UploadText(
“This is the default content of my blob.”);
First of all I had to create a container and after that I created a blob. I blob need to be part of a container. I set the ContentType of the blob to text to be more easily to test, but we could set any content type.After we have an instance to the blob, we can create a Shared Access Signature.
var sharedAccessSignature = myBlob.GetSharedAccessSignature(
new SharedAccessPolicy()
{
Permissions = SharedAccessPermissions.Write
| SharedAccessPermissions.Read
SharedAccessExpiryTime = DateTime.UtcNow +
TimeSpan.FromHours(1);
}
string sharedAccessSignatureUri = blob.Uri.AbsoluteUri + sharedAccessSignature;
In the above code we created a SharedAccessSignature that is valid for 1 hour. In this time the user can read or write any content on our blob. Now, let’s see how the user can use the generated URL to access our blob:var storageCredentialsSAS = new StorageCredentialsSharedAccessSignature(
sharedAccessSignature);
var blobClient = new CloudBlobClient(myAccount.BlobEndpoint,
storageCredentialsSAS);
var myBlob = blobClient
.GetBlobReference(“myContainer/firstBlob.txt”);
string currentContentOfBlob =
myBlob.DownloadText();
myBlob.UploadText(“New text appended”);
From what we can see, for the client is very easy to access and consume data from the blob. From the all process of creating, sending (share) and use a Shared Access Signature I think that the most complicated think to do is to send the shared key to the consumer.Tutorials about Shared Access Signature:
- Overview
- How to use Shared Access Signature with tables from Windows Azure
- How to use Shared Access Signature with blobs from Windows Azure
- How to use Shared Access Signature with queues from Windows Azure
- How to remove or edit a Shared Access Signature from Windows Azure
- Some scenarios when we can use Shared Access Signature from Windows Azure
Comments
Post a Comment