There's more than one way too...connect your Windows Phone 7 to Dropbox via SevenDrops

Sign in to queue


Recently I posted about a a library that provides an interface between your Windows Phone 7 and Dropbox, Dropping in on Dropbox with DropNet. The beauty, and challenge, of software development is that there's always multiple ways to approach any problem.

Den Delimarsk has recently post a six step tutorial series on DZone about uploading your Windows Phone 7 pictures to Dropbox, Developing SevenDrops - A Dropbox-based photo uploader for Windows Phone 7 [6/6] 

[Den Delimarsk sound familiar? Yep, it was his work I highlighted in the last post, "LED fun, four characters at a time, with Netduino and ShieldStudio". What's funny is that I didn't plan that at all, having stuff from him back to back. I was just focused on the content and wanted a hardware topic and a WP7 topic for this set and I've been wanting to post about SevenDrops project since I first saw it. It didn't dawn on me that these two were from the person until I was well into the the post writing planning stage. But since the topics are so dissimilar, I guess this is just going to be a Den By Default 2-fer week Wink ]

What I liked about this series is that Den walks us through his journey in building this exploratory app, his "wouldn't it be cool it" and "gee, I wonder how to code against this API" journey. Starting with Part 1;

If you didn't know this yet, Dropbox is a cloud storage service service that allows you to store files on their servers and then access those from anywhere. This service exposes a public API that I decided to integrate in a Windows Phone 7 application to backup my photos. SkyDrive integration is great but I was just curious about an implementation for Dropbox, so this set of articles describes the way I built the application


Thought Part 6;

This is the last piece of my tutorial set that describes the way to upload files to Dropbox from a Windows Phone application. The core is pretty much completed right now and all that needs to be done is to properly handle the actual upload process (read: make sure the user knows what's going on). Here are some details on the additions I made to the existing application skeleton.


Here's all six parts;

You're right, it's code time which is hosted on CodePlex, SevenDrops;

SevenDrops is a Windows Phone photo uploader that allows the user to backup photo content to Dropbox. It has a fairly basic UI that facilitates a fast "launch-and-upload" experience.

The project is not based on any third-party libraries and carries my own Dropbox API wrapper.

The code is simple and approachable. It's also complete unto itself. As Den states, there's no third party libraries used at all. When learning a new API sometimes it's just easier to grok when you've got it all in one place and the code is focused on the specific task at hand.


The magic is in the uploading. It's kicked of in the UI via the button1 click event;

private void button1_Click(object sender, RoutedEventArgs e)
string token = IsolatedStorageSettings.ApplicationSettings["token"].ToString();
string tokenSecret = IsolatedStorageSettings.ApplicationSettings["secret"].ToString();

App.uploadCounter.Counter = ImageList.Items.Count;

foreach (ImageUnit unit in Images)
OAuth.OAuthClient.Upload(unit.ImageName, unit.ImageContents, token, Helpers.Constants.ApiKey, Helpers.Constants.ConsumerSecret, tokenSecret);

Popup uploadPopup = new Popup();
uploadPopup.Child = new UploadingFiles();
uploadPopup.IsOpen = true;
uploadPopup.VerticalOffset = 100;
uploadPopup.HorizontalOffset = 25;

Binding b = new Binding();
b.Source = App.uploadCounter;
b.Converter = new CounterToVisibilityConverter();
b.Path = new PropertyPath("Counter");
uploadPopup.SetBinding(Popup.IsOpenProperty, b);

And executed in the OAuth.OAuthClient.Upload method;

public static void Upload(string name, byte[] content, string token, string apiKey, string consumerSecret, string tokenSecret)
Dictionary<string, string> parameters = new Dictionary<string, string>();

parameters.Add("oauth_consumer_key", apiKey);
parameters.Add("oauth_signature_method", "HMAC-SHA1");
parameters.Add("oauth_timestamp", CurrentUNIXTimestamp.Get());
parameters.Add("oauth_nonce", Guid.NewGuid().ToString().Replace("-", ""));
parameters.Add("oauth_token", token);
parameters.Add("oauth_version", "1.0");
parameters.Add("file", name);

string OAuthHeader = GetOAuthHeader(parameters, "POST", "", consumerSecret, tokenSecret);

string boundary = Guid.NewGuid().ToString();
string header = "--" + boundary;
string footer = "--" + boundary + "--";

HttpWebRequest uploadRequest = (HttpWebRequest)WebRequest.Create("");
uploadRequest.ContentType = "multipart/form-data; boundary=" + boundary;
uploadRequest.Method = "POST";
uploadRequest.Headers["Authorization"] = OAuthHeader;

StringBuilder headers = new StringBuilder();
headers.AppendLine("Content-Disposition: file; name=\"file\"; filename=\""+ name +"\"");
headers.AppendLine("Content-Type: application/octet-stream");
headers.AppendLine(Encoding.GetEncoding("iso-8859-1").GetString(content, 0, content.Length));

byte[] contents = Encoding.GetEncoding("iso-8859-1").GetBytes(headers.ToString());

object[] data = new object[2] { uploadRequest, contents };
uploadRequest.BeginGetRequestStream(new AsyncCallback(GetData), data);


Page thumbnail curtsey of divemasterking2000

The Discussion

Add Your 2 Cents