AzureCopy assembly howto…

Now that AzureCopy has been split into a client executable and associated dll, it’s now possible to use the dll for your own applications. In this example I’ll show how to write a simple application to copy files from S3 to Azure Blob Storage. (again, for practical reasons I’d suggest using azurecopy executable itself… but hey, for those that want to code below are the steps required).

Firstly, learn to love Nuget. It the one stop shop for all your .NET assemblies and other dependencies. Assuming you know how to use it (if not, please see docs), add the “azurecopy” reference to your application. (in my case I’ll be creating a simple console app).

The AzureCopy dll has a number of key classes that implement the same simple interface. IBlobHandler is simply

public interface IBlobHandler
    Blob ReadBlob(string url, string filePath = “”);

    void WriteBlob(string url, Blob blob,  int parallelUploadFactor=1, int chunkSizeInMB=4);

    List<string> ListBlobsInContainer(string baseUrl);

I think the interface is fairly self explainatory.

– ReadBlob reads the blob stored at a given URL (with optional filePath if you want to cache it on local storage before copying to another cloud location).

– WriteBlob writes a blob to a given URL. Uploading can be performed in parallel for some cloud providers. You can specify the level of parallelism as well as how large those parallel chunks should be. These features will be expanded with future releases.

– ListBlobsInContainer is well, given a URL, list the blob contents (non-recursively).

Currently AzureCopy reads all its configuration from an App.Config file. Ideally these configurations will get injected by the client app, but for now, App.Config works fine.

Beyond the usual App.Config boilerplate, the entries needed are:

<add key=”AzureAccountKey”value=”/>
<add key=”AWSAccessKeyID” value=”” />
<add key=”AWSSecretAccessKeyID” value=”” />

The AzureAccountKey can be retrieved from the Azure Portal , likewise the AWS (S3) details are directly from Amazons Portal.

Now to the code.  There are only 2 lines of “real” code, one to read the blob and one to write (and hopefully you can figure out which is which) Smile

var sourceHandler = new S3Handler();
var targetHandler = new AzureHandler();

var s3Url = “”;
var azureUrl = “”;

var blob = sourceHandler.ReadBlob(s3Url);

targetHandler.WriteBlob(azureUrl, blob);

In this case I want to copy from the S3 URL and write into the azureURL. The blob is stored in the S3 bucket “testabc123” (made up) and is writing to the Azure Storage account “myblobstorage” (again, made up) and put into the “temp” container.

This is just a starter on how to use AzureCopy assembly. In future posts I’ll go over more complex scenarios such as copying multiple files, asking Azure to do the copying for you (so you dont use any bandwidth!!!) among other things.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s