There are two main open source .net Amazon S3 libraries.
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();
}
For data that does not require immediate retrieval, you can set up S3 Intelligent-Tiering to monitor and automatically move objects that aren't accessed for 180 days or more to the Deep Archive Access tier to realize up to 95% in storage cost savings. There are no retrieval charges in S3 Intelligent-Tiering.
Flexibility: S3 is ideal for a wide range of uses like data storage, data backup, software delivery, data archiving, disaster recovery, website hosting, mobile applications, IoT devices, and much more.
One Zone-IA, Glacier and Glacier Deep Archive are the most appropriate Amazon S3 storage classes for long-term archival.
All objects are stored in S3 buckets and can be organized with shared names called prefixes. You can also append up to 10 key-value pairs called S3 object tags to each object, which can be created, updated, and deleted throughout an object's lifecycle.
Looks like the official library is now 'AWS SDK for .NET', available here: http://aws.amazon.com/sdkfornet/
Looks like it includes:
It supports:
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With