Use within Silverlight Upload App

Mar 2, 2009 at 10:49 PM
I am writing a Silverlight 2.0 upload app which will upload directly to Amazon S3 buckets from the client browser in order to be able to upload large (over 1GB) files without having to upload to the webserver first while still recording the file on the webserver's DB. Can anyone tell me if they have been able to do this using any of the ThreeSharp code?

I would like to use file chunking and progress feedback.

Many thanks

Richard
Coordinator
Mar 7, 2009 at 5:00 PM
Hi Richard,
  Unfortunately, you can't just add a .NET assembly to a Silverlight project, because the Silverlight plugin only implements a subset of the full .NET framework.  David Betz documents this pretty well here: http://www.netfxharmonics.com/2008/12/Reusing-NET-Assemblies-in-Silverlight

  In theory, you could create a new Silverlight Assembly project, add all the ThreeSharp .cs files and try to compile.  However, ThreeSharp uses a number of .NET objects that are not implemented in the Silverlight plugin.  An example would be the System.Xml namespace.  It's possible to work around this.  There are probably alternate objects that would accomplish the same objectives.  It would be a small project though.

  I do see one big roadblock.  Silverlight is very picky about security when connecting to servers other than the one hosting the .xap file.  You can get around this if you have control of the remote server and can put a crossdomain.xml and clientaccesspolicy.xml file on it.  I don't know whether Amazon has these, but I would guess probably not.  If they don't, the usual workaround is to route all your web service traffic through a proxy service on your own server.  But that's what you're trying to avoid here.

  I'll talk to Amazon about this.

Thanks,
Joel Wetzel
Affirma Consulting
Mar 8, 2009 at 1:13 PM
Hi Joel,

thanks for the guidance. My intention was to use the code ported to silverlight if that was OK with the developers as I realised I could not simply call .NET dlls from silverlight. That said I have also found the following article on S3 about cross domain policy files and granting access to the silverlight client control:

http://developer.amazonwebservices.com/connect/entry.jspa?externalID=2011&ref=featured

I will continue to investigate and look into any other options as I think this could be a very useful tool for those developing apps with cloud storage who wish to upload direct from client browsers rather than through the web server host.

We will of course post any code we develop (if it's any good :-)  for all to use.

Best Regards

Richard


Mar 17, 2009 at 4:19 PM
Hi Richard and Joel,  
I also am looking to port the threesharp code to run in silverlight.  
I was able to get silverlight to communicate with s3 via http: and https:.  
I want the ability to to upload larger objects > 1mb.  
Now I am looking for the best methods to accomplish this.

Regards,
John
Apr 24, 2009 at 10:18 PM
You'll want to be careful what you do, from a security standpoint. It's easy to open XAP files and disassemble the code to see your constants (e.g. amazon secret keys). An obfuscation tool might help but I'd still be careful.
Jun 23, 2009 at 7:33 PM

I also need to get Silverlight to upload files > 1MB - is there any progress on this?  Any suggestions?

I'll give anyone who helps me find the solution a free lifetime membership to www.iTabletop.com for gaming software and/or video conference collaboration software ($200.00 value).

Thanks in advance!

James Auld

May 7, 2010 at 6:36 PM

We just finished created an S3 Upload library.  It will upload files up to 5 GB (the Amazon S3 size limit).  It uses a stream for uploading so the file isn't cached in memory and it uses an event model so you can report upload progress back to your users.  I've also built it to use good security practices and discourage you from storing your AWS Secret Key in your silverlight app and by defualt it uploads to S3 using SSL, but you can disable that via a UseSSL property if you'd like.  There's sample code and more information on the site.

Here's the link if you're interested in downloading the trial.  We're also interested in building a base of beta testers for new versions as well which would include some free licensing.  If you're interested, check out the trial and fill out the contact form on the site.

http://www.parentelement.com/products/slights3

 

 

Jul 26, 2010 at 6:17 PM

I've been messing around with this library trying to port it over to Silverlight.  From what I've found using the HttpWebRequest class to upload files via the S3 REST interface is not possible because using the PUT verb for the Method property is not supported.  I image the best solution would be to derive a new class S3WebRequest from the WebRequest abstract class and go from there.

I've been able to port it over for downloading files though.  Although from what I've found the HttpWebRequest does not support adding custom headers when using the GET verb so I had to use a query string method instead.  If anyone wants me to post an example of my code just let me know.

For my purposes all I need to do is download and would like to figure out a solution to upload.  Is there any other way to upload to S3 other than using the REST interface?

Aug 16, 2010 at 1:47 PM

m1is -

The problem is that with Silverlight versions prior to Silverlight 4 there was no way to disable write stream buffering.  The class library we build that I linked in my previous reply constructs a POST, but it uses Silverlight 4.  It also disables buffering and reports progress back to the UI.  The problem with using Silverlight 3 and below and not being able to disable the buffering is:

1.  You cannot get progress for your uploads.

2.  The entire file is buffered in browser memory, even if you specify to use ClientHTTP.

So since the entire file would be buffered, if you were uploading a 1 Gig file, you would consume 1 gig of RAM, which is bad for the client.  I put a lot of time into communicating with the Silverlight dev team to get them to allow for unbuffered uploads with Silverlight 4.  Our class library is priced at $99, you should at least go read the documentation.  It may save you a lot of time and effort.

Aug 16, 2010 at 7:32 PM

I ended up using the client stack for my requests instead of the browser stack and all my troubles went away.  Before I discovered the client stack I tried POST for uploading but in the end found it much easier with the REST/PUT via the client stack.  Also since I am using the client stack I can disable read and write stream buffering for uploads and downloads and include a progress indicator.  I've been testing uploading and downloading of a 1 GB file without any issues.

Aug 16, 2010 at 7:35 PM

That's almost exactly the route I took, except using POST.  I wasn't sure what hte capabilities were for adding custom META tags and setting ACL's via the PUT method (and using SSL) so I opted for POST because it let me accomplish all of it.

Aug 16, 2010 at 11:02 PM

Thanks to the client stack I am able to add custom headers and set ACLs on PUT requests and I am also able to read back the headers through HEAD requests.