Geo*_*Geo 17 .net asp.net-mvc amazon-s3
有两个主要的开源.net Amazon S3库.
我目前在MVC演示项目中使用LitS3,但有一些批评.有没有人在这里使用这两个库,所以他们可以给出一个客观的观点.
下面是一些使用LitS3的示例调用:
在演示控制器上:
private S3Service s3 = new S3Service()
{
AccessKeyID = "Thekey",
SecretAccessKey = "testing"
};
public ActionResult Index()
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";
return View("Index",s3.GetAllBuckets());
}
Run Code Online (Sandbox Code Playgroud)
在演示视图中:
<% foreach (var item in Model)
{ %>
<p>
<%= Html.Encode(item.Name) %>
</p>
<% } %>
Run Code Online (Sandbox Code Playgroud)
编辑1:
由于我必须继续移动,并且没有明确指示哪个库更有效并且保持更新,我已经实现了一个存储库模式,其中包含一个接口,如果将来需要,我可以更改库.下面是我创建的S3Repository的一部分,如果需要,我将允许我更改库:
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
Run Code Online (Sandbox Code Playgroud)
如果您有关于此问题的任何信息,请在评论中告诉我,我将返回并编辑问题.
编辑2: 由于这个问题没有得到关注,我在我的网络应用程序中集成了两个库以查看设计上的差异,我知道这可能是一段时间,但我真的想要一个好的长期解决方案.下面你将看到两个与两个库相同动作的样本,也许这会激励你们中的一些让我知道你的想法.
有三个SHARP图书馆:
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();
}
Run Code Online (Sandbox Code Playgroud)
与LITS3图书馆:
public IQueryable<T> FindAllBuckets<T>()
{
return _repository.GetAllBuckets()
.Cast<T>()
.AsQueryable();
}
Run Code Online (Sandbox Code Playgroud)
Dan*_*rza 14
看起来官方库现在是' AWS SDK for .NET ',可在此处获取:http://aws.amazon.com/sdkfornet/
看起来它包括:
它支持:
我可以顺便说一句,我们使用 Affirma ThreeSharp 大概有一年左右的时间了。我很确定我们第一次使用 S3 时使用的是 Amazon 的 SOAP 库,这肯定不如 Affirma 的 ThreeSharp 那么容易。
我还发现它非常可靠,即使在进行批量工作和上传/下载大量数据时也是如此。项目似乎没有更新那么多,但我们并没有觉得它曾经需要更新!
代码示例:类似这样的内容将上传文件:
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))
{ }
}
Run Code Online (Sandbox Code Playgroud)
编辑:Amazon 现在为其 Web 服务(包括 S3)推出了自己的 .Net 库,因此 Affirma 不再支持他们的库。
http://aws.amazon.com/sdkfornet/
| 归档时间: |
|
| 查看次数: |
4900 次 |
| 最近记录: |