有人有使用 ASP .Net 创建带有过期时间的签名 URL 的示例吗?我正在探索使用 LitS3或ThreeSharp在我的项目中,并且没有在这些项目中看到任何具体方法来执行此操作。谢谢。
最佳答案
以下是我使用 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));
}
}
关于asp.net - 使用 ASP .Net 创建指向 S3 或 Cloudfront 托管内容的过期链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1607805/