views:

1024

answers:

3

There are two main open source .net Amazon S3 libraries.

  1. Three Sharp
  2. LitS3

I am currently using LitS3 in our MVC demo project, but there is some criticism about it. Has anyone here used both libraries so they can give an objective point of view.

Below some sample calls using LitS3:

On demo controller:

    private S3Service s3 = new S3Service()
    {
        AccessKeyID = "Thekey",
        SecretAccessKey = "testing"
    };

    public ActionResult Index()
    {
        ViewData["Message"] = "Welcome to ASP.NET MVC!";

        return View("Index",s3.GetAllBuckets());
    }

On demo view:

<% foreach (var item in Model)
   { %>
   <p>
    <%= Html.Encode(item.Name) %>
   </p>
<% } %>

EDIT 1:

Since I have to keep moving and there is no clear indication of what library is more effective and kept more up to date, I have implemented a repository pattern with an interface that will allow me to change library if I need to in the future. Below is a section of the S3Repository that I have created and will let me change libraries in case I need to:

using LitS3;

namespace S3Helper.Models
{
  public class S3Repository : IS3Repository
  {
    private S3Service _repository;
    #region IS3Repository Members

    public IQueryable<Bucket> FindAllBuckets()
    {
        return _repository.GetAllBuckets().AsQueryable();
    }

    public IQueryable<ListEntry> FindAllObjects(string BucketName)
    {
        return _repository.ListAllObjects(BucketName).AsQueryable();
    }

    #endregion

If you have any information about this question please let me know in a comment, and I will get back and edit the question.

EDIT 2: Since this question is not getting attention, I integrated both libraries in my web app to see the differences in design, I know this is probably a waist of time, but I really want a good long run solution. Below you will see two samples of the same action with the two libraries, maybe this will motivate some of you to let me know your thoughts.

WITH THREE SHARP LIBRARY:

    public IQueryable<T> FindAllBuckets<T>()
    {
        List<string> list = new List<string>();

        using (BucketListRequest request = new BucketListRequest(null))
        using (BucketListResponse response = service.BucketList(request))
        {
            XmlDocument bucketXml = response.StreamResponseToXmlDocument();
            XmlNodeList buckets = bucketXml.SelectNodes("//*[local-name()='Name']");
            foreach (XmlNode bucket in buckets)
            {
                list.Add(bucket.InnerXml);
            }
        }
        return list.Cast<T>().AsQueryable();
    }

WITH LITS3 LIBRARY:

    public IQueryable<T> FindAllBuckets<T>()
    {
        return _repository.GetAllBuckets()
            .Cast<T>()
            .AsQueryable();
    }
+3  A: 

I can chime in by saying that we have been using Affirma ThreeSharp for perhaps a year or so. I'm pretty sure the first time we were using S3 we were using Amazon's SOAP library which was certainly not as easy as Affirma's ThreeSharp.

I have also found it to be very reliable, even when doing batch work and uploading / downloading large amounts of data. Project doesn't seem to get updated that much, but then we haven't felt like it was ever in need of being updated!

Code example: Something like this will upload a file:

m_config = new ThreeSharpConfig
                           {
                               AwsAccessKeyID = Core.ConfigSettings.AmazonS3AccessKey,
                               AwsSecretAccessKey = Core.ConfigSettings.AmazonS3SecretAccessKey,
                               ConnectionLimit = 40,
                               IsSecure = true

                           };
            m_service = new ThreeSharpQuery(m_config);



 using (var request = new ObjectAddRequest(amazonS3BucketName, fileName.Replace(' ', '_')))
            {
                request.Headers.Add("x-amz-acl", "public-read-write");
                request.LoadStreamWithBytes(fileData);

                if (redirectUrl != null)
                {
                    request.RedirectUrl = redirectUrl;
                }

                using (ObjectAddResponse response = m_service.ObjectAdd(request))
                { }
            }

Edit: Amazon have now launched their own .Net library for their web services (including S3) so consequently Affirma are no longer supporting their library.
http://aws.amazon.com/sdkfornet/

Perhentian
Hi Perhentian: How do you feel about the lack of object design in Affirma's library. They make you process the XML, is there any other way, I am missing something? any input on that?
Geo
Hi Geo, Actually I haven't gone near any XML. You should be able to upload a file in just a few lines of C#. Have a look at their sample project.
Perhentian
+1  A: 

I've had better luck with LitS3. The ThreeSharp one was uploading files with 0 bytes from time to time and frankly is a bit over-engineered for the problem it's solving.

Alexei White
+6  A: 

Looks like the official library is now 'AWS SDK for .NET', available here: http://aws.amazon.com/sdkfornet/

Looks like it includes:

  • Code samples
  • Visual Studio integration
  • .NET library code

It supports:

  • Amazon Elastic Compute Cloud
  • Amazon Simple Storage Service
  • Amazon Virtual Private Cloud
  • Amazon SimpleDB
  • Amazon Relational Database Service
  • Amazon CloudFront
  • Amazon Simple Queue Service
  • Amazon Simple Notification Service
  • Amazon Elastic MapReduce
  • Amazon CloudWatch
  • Elastic Load Balancing
  • Auto Scaling
Dan Esparza