创建到期链接到S3或者的Cloudfront托管内容的ASP.NET链接、内容、Cloudfront、ASP

2023-09-11 09:16:59 作者:转身、已不在

任何人都有创造一个标识的URL使用ASP .NET中过期的例子吗?我使用的是探索 LitS3 或的 ThreeSharp 在我的项目,并没有看到任何具体的方法来做到这一点在任何这些项目。谢谢你。

Anyone have an example of creating a signed URL with an expiration using ASP .Net? I'm exploring using LitS3 or ThreeSharp in my project, and have not seen any specific methods to do this in either of those projects. Thanks.

推荐答案

下面的(基于以上问题的答案,我发现上的 http://www.ec2studio.com/articles/s3.html ):

Here's what worked for me with the AWS SDK and MVC 3 (based on the answers above and what I found on 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));
        }
}
 
精彩推荐
图片推荐