Project Description
Large File Uploader in Silverlight shows how to break a file into manageable Base64 encoded chunks and send them over HTTP to a web server. Threading is implemented to keep the UI responsive including Pause/Resume support while the session is still running.

This code and solution were created using VS.Net 2010 Express Edition with Silverlight 4.0 and the Silverlight 4.0 SDK

Quick look at the heart of the code here

Bakground

Uploading very large files to web sites comes at a price. Direct web uploads of large files often die or become down right impossible when as you move from 10MG to 1GB upload size. Web Servers often reject submitted files only after the user waits for multiple hours and finally gets back an error like file too big, unsupported extension or server/client timeouts. People have tried Java, Flash, Gears, Active-X, HTTP and they all have their own limits and platform support issues and even more complications arise when the file gets very large and the coder never took that into account. Something that works fine on a small file may not work so well on a very large 2GB (or larger) size file.

What I have here is a no fuss example using Silverlight to split a file into chunks for sending to a web server. Please note that this code is not intended for a production environment or LOB application as it's implemented. There's no security, no CRC checks or file upload authentication checks. This code is only an example of how it can be done while keeping things light weight, simple and responsive.

I did use Base64 encoding for the file chunks and this adds overhead as the file gets larger but the growth limit is 1.3x the file size. To offset this I've enabled the sample with the ability to spin up more than one HTTP chunk transfer at a time. For IE8 I believe connection limit is 8 to a domain but typically you would only want 2. Your mileage per browser client will vary but it's safer to keep the limit at 2 (where the RFC spec intended.) If your playing to a broader audience and running AJAX in your page aside from this tool then throttle it down to only 1 connection in the code or the via the JavaScript hooks.

There is no error handling within this code as I wanted to keep the code simple enough to understand. The web page that receives the file StoreFile.ashx writes the exact same file name to disk. If there is an error the system attempt to roll back and re-send the last few blocks.

Additional information on starting a new project is available here: Project Startup Guide.

Last edited Mar 5, 2012 at 3:17 AM by ZombieBob, version 7