CloudBlob Constructor (String, StorageCredentials)

Updated: April 24, 2013

[This topic is part of the Microsoft Azure Storage Client Library 1.7, which has been deprecated. See Storage Client Library for the latest version.]

Initializes a new instance of the CloudBlob class using an absolute URI to the blob and a set of credentials.

Namespace: Microsoft.WindowsAzure.StorageClient
Assembly: Microsoft.WindowsAzure.StorageClient (in Microsoft.WindowsAzure.StorageClient.dll)

'Usage
Dim blobAbsoluteUri As String
Dim credentials As StorageCredentials

Dim instance As New CloudBlob(blobAbsoluteUri, credentials)

public CloudBlob (
	string blobAbsoluteUri,
	StorageCredentials credentials
)

Parameters

blobAbsoluteUri

Type: System.String

The absolute URI to the blob.

credentials

Type: Microsoft.WindowsAzure.StorageCredentials

The account credentials.

The following code example creates a new blob using an absolute URI and storage credentials.

static void WriteToBlobViaSAS1(Uri blobEndpoint, string accountName, string accountKey)
{
    // Create service client for credentialed access to the Blob service.
    CloudBlobClient blobClient = new CloudBlobClient(blobEndpoint, new StorageCredentialsAccountAndKey(accountName, accountKey));

    CloudBlob blob = blobClient.GetBlobReference("mycontainer/myblob.txt");

    // Upload text to the blob, which will create it if it does not already exist.
    blob.UploadText("a text blob");

    // Create a shared access signature to use for delegated access to the blob.
    // Specify an access policy that indicates the start time, expiry time, and permissions granted for the signature.
    string signature = blob.GetSharedAccessSignature(new SharedAccessPolicy()
    {
        // If valid immediately, don’t set SharedAccessStartTime. To avoid clock skew, use a duration of less than one hour.
        // SharedAccessStartTime = DateTime.Now,
        // Specify the expiration time for the signature.
        SharedAccessExpiryTime = DateTime.Now.AddMinutes(55),

        // Specify the permissions granted by the signature.
        Permissions = SharedAccessPermissions.Write | SharedAccessPermissions.Read
    });

    // Get a reference to the blob using the shared access signature.
    CloudBlob blobSAS = new CloudBlob("http://storagesample.blob.core.windows.net/mycontainer/myblob.txt", new StorageCredentialsSharedAccessSignature(signature));

    // Update the contents of the blob, then read them.
    blobSAS.UploadText("a text blob updated using a shared access signature");

    Console.WriteLine(blobSAS.DownloadText());
}

Development Platforms

Windows Vista, Windows 7, Windows Server 2008, Windows 8.1, Windows Server 2012 R2, Windows 8 and Windows Server 2012

 

Reference

CloudBlob Class
CloudBlob Members
Microsoft.WindowsAzure.StorageClient Namespace

Other Resources

Naming and Referencing Containers, Blobs, and Metadata

Show: