示例#1
0
 /// <summary>
 /// Takes a key and a bucket and converts the
 /// path into a presigned url for access to restricted
 /// S3 content.
 /// </summary>
 /// <param name="bucket">The bucket that the object is in.</param>
 /// <param name="key">The path to the object in S3.</param>
 /// <param name="expiresIn">The amount of minutes from now to expire the URL from.</param>
 /// <param name="protocol">The protocol of the URL to request. Default is HTTP.</param>
 /// <returns></returns>
 public static string PreSignURL(string bucket, string key, double expiresIn = 5, Amazon.S3.Protocol protocol = Amazon.S3.Protocol.HTTP)
 {
     string url = string.Empty;
     using (Amazon.S3.IAmazonS3 client = new Factory().S3Client())
     {
         Amazon.S3.Model.GetPreSignedUrlRequest request = new Amazon.S3.Model.GetPreSignedUrlRequest()
         {
             BucketName = bucket,
             Key = key,
             Protocol = protocol,
             Expires = DateTime.Now.AddMinutes(expiresIn)
         };
         url = client.GetPreSignedURL(request);
     }
     return url;
 }