using System;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
namespace BlobsInCDN
{
class Program
{
static void Main(string[] args)
{
//Specify storage credentials.
StorageCredentialsAccountAndKey credentials = new StorageCredentialsAccountAndKey("storagesample",
"m4AHAkXjfhlt2rE2BN/hcUR4U2lkGdCmj2/1ISutZKl+OqlrZN98Mhzq/U2AHYJT992tLmrkFW+mQgw9loIVCg==");
//Create a reference to your storage account, passing in your credentials.
CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, true);
//Create a new client object, which will provide access to Blob service resources.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
//Create a new container.
CloudBlobContainer container = blobClient.GetContainerReference("cdncontent");
container.CreateIfNotExist();
//Specify that the container is publicly accessible.
BlobContainerPermissions containerAccess = new BlobContainerPermissions();
containerAccess.PublicAccess = BlobContainerPublicAccessType.Container;
container.SetPermissions(containerAccess);
//Create a new blob and write some text to it.
CloudBlob blob = blobClient.GetBlobReference("cdncontent/testblob.txt");
blob.UploadText("This is a test blob.");
//Set the Cache-Control header on the blob to specify your desired refresh interval.
blob.SetCacheControl("public, max-age=31536000");
}
}
public static class BlobExtensions
{
//A convenience method to set the Cache-Control header.
public static void SetCacheControl(this CloudBlob blob, string value)
{
blob.Properties.CacheControl = value;
blob.SetProperties();
}
}
}
Comments
0 comments
Please sign in to leave a comment.