Asynchronous upload

Dec 17, 2008 at 12:45 PM
I'm trying to use this Upload component for ASP.NET with Amazon S3.

http://darrenjohnstone.net/2008/07/15/aspnet-file-upload-module-version-2-beta-1/

He has a really nice interface implementation where you can create you own "backend" and he provide one for the filesystem and for a SQL database. And needles to say i am trying to implment one for Amazon S3. Bascily the interface specifies a StartNewFile method, a Write method and a EndFile file method. The Write method sends back status messages to a progressbar. My problem is that i cant figure out how to upload a file "piece by piece" ..

I do something like this now.

StartNewFile(string fileName, string contentType, Dictionary<string, string> headerItems, Dictionary<string, string> previousFields)
request = new ObjectAddRequest("audio.whoa.nu", _fileName.Replace(' ', '_'));
request.Headers.Add("x-amz-acl", "public-read");
request.DataStream = new MemoryStream();

Write(byte[] buffer, int offset, int count)
request.DataStream.Write(buffer, offset, count);
request.DataStream.Flush();

EndFile
request.DataStream.Position = 0;
request.BytesTotal = request.DataStream.Length;

ObjectAddResponse objectAddResponse = service.ObjectAdd(request);
objectAddResponse.DataStream.Close();


This works but the problem is that all the works get done in the "EndFile" method and therefore the progressbar just goes to 100%. Then the upload starts and after a while its done. I want the work to get done in the "Write" method. As far as i understand it i only writing the file byte by byte into the servers memory now?

I admit i suck big time with streams, responses and requests .. i just want stuff to work the way i want to ;)

I would grealty appricate some help with this. I cant imagine it is that hard ..

Br, Ola