I’ve been asked a question on how to use the AzureCopy Nuget package to copy between Azure and Dropbox. Admittedly this is slightly easier to do with the AzureCopy command than with the Nuget assembly. So here’s a quick rundown on how to do this.
Firstly, you need to register AzureCopy (whether it’s the command or assembly).
For the command the process is very simple:
You simply need to run the command: azurecopy –configdropbox
and follow the instructions.
The config file azurecopy.exe.config will be modified to include 2 new entries, DropBoxUserSecret and DropBoxUserToken. These 2 new entries are the secret/token for azurecopy.exe to be able to access your Dropbox files.
AzureCopy Nuget package
If you’re using the AzureCopy Nuget package, this means you’re creating a new application to access Dropbox (and other cloud storage services). To register your new app with Dropbox you’ll need to go to the registration portal. Once you’ve done that you’ll receive a DropBoxAPIKey and DropBoxAPISecret. These are yours (the developer) and shouldn’t be shared with the general public, for this reason I’ve setup the AzureCopy assembly to read these values from 2 locations. One is the app.config which is fine if you (or your company) are the only ones using your application.
The other location it reads these values from are embedded in the source code. Specifically the class APIKeys has 2 static public string member variables, DropBoxAPIKey and DropBoxAPISecret. If the variables cannot be read from the app.config it will be read from this file. This allows the distribution of the key/secret to other parties without making it obvious what the values are. Obviously if you’re purely using the Nuget package then modifying the source is not possible and the app.config is your only option. If you prefer the source code approach then github has all you need.
Now that you’ve got this far (remember, you’ll only need to do this once) you still need to go through the steps similar to what we did above for the AzureCopy command. You’ll need to generate the Dropbox authorization url and have the user enter it into a browser and allow your new application to their Dropbox. To generate the authorization url you can simply use the static method DropboxHelper::BuildAuthorizeUrl which returns a string url.
This may sound like a lot of work but is really about 2 minutes of effort.
Blob Copy Code
Once you’ve registered your new app with Dropbox portal and have authorized your new app, the code to copy between Azure (for example) and Dropbox is very straight forward.
The simplest case in C# is:
(assuming the Azure credentials have already been updated in the app.config)
// Create an Azure “Handler” which is used to process all Azure requests.
var azureHandler = new AzureHandler();
// Create a Dropbox “handler” ditto.
var dropboxHandler = new DropboxHandler();
// full url to Azure Blob
var inputUrl = “https://dummyurl.blob.core.windows.net/myazureblob”;
// url to Dropbox folder where the blob will be copied too.
var outputUrl = “https://dropbox.com/mydropboxfolder/”;
// read the blob
var blob = azureHandler.ReadBlob(inputUrl);
// write the blob