任何人有创建使用ASP.NET的到期签署的URL的例子吗? 我使用的是探索LitS3或ThreeSharp在我的项目,并没有看到任何具体的方法在任何这些项目的做到这一点。 谢谢。
Answer 1:
下面是与AWS SDK和MVC 3为我工作(基于以上问题的答案,我上找到http://www.ec2studio.com/articles/s3.html ):
public ActionResult GetS3Object(string bucket, string key)
{
string accessKeyID = ConfigurationManager.AppSettings["AWSAccessKey"];
string secretAccessKeyID = ConfigurationManager.AppSettings["AWSSecretKey"];
using (AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKeyID, secretAccessKeyID))
{
GetPreSignedUrlRequest request = new GetPreSignedUrlRequest()
.WithBucketName(bucket)
.WithKey(key)
.WithExpires(DateTime.Now.Add(new TimeSpan(7, 0, 0, 0)));
return Redirect(client.GetPreSignedURL(request));
}
}
Answer 2:
使用亚马逊的.NET SDK就可以得到preSignedUrl
using (AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client("your access key ID", "you secret key"))
{
GetPreSignedUrlRequest getPreSignedUrl = new GetPreSignedUrlRequest().WithBucketName(bucketName);
getPreSignedUrl.Key = key;
getPreSignedUrl.Expires = DateTime.Now.AddSeconds(60);
}
Answer 3:
发现这个 (中提到的这个线程在AWS论坛)类库在Amazon S3中生成签署的网址。 如果任何人有任何其他建议/方法来尝试,让我知道。
编辑:ThreeSharp有我一直在寻找的功能。 从ThreeSharpConsoleSample应用:
using (UrlGetRequest request = new UrlGetRequest("mytestbucket", "mytestfile.txt"))
{
request.ExpiresIn = 60 * 10000;
using (UrlGetResponse response = service.UrlGet(request))
{
Console.WriteLine("Try this url in your web browser (it will only work for 60 seconds)\n");
string url = response.StreamResponseToString();
Console.WriteLine(url);
}
}
Console.WriteLine("\npress enter >");
Console.ReadLine();
文章来源: Creating expiring links to S3 or Cloudfront hosted content with ASP .Net