当前位置: 首页>>代码示例>>C#>>正文


C# AmazonS3.GetPreSignedURL方法代码示例

本文整理汇总了C#中AmazonS3.GetPreSignedURL方法的典型用法代码示例。如果您正苦于以下问题:C# AmazonS3.GetPreSignedURL方法的具体用法?C# AmazonS3.GetPreSignedURL怎么用?C# AmazonS3.GetPreSignedURL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AmazonS3的用法示例。


在下文中一共展示了AmazonS3.GetPreSignedURL方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoesS3BucketExist

 public static bool DoesS3BucketExist(string bucketName, AmazonS3 s3Client)
 {
     bool flag;
     if (s3Client == null)
     {
         throw new ArgumentNullException("s3Client", "The s3Client cannot be null!");
     }
     if (string.IsNullOrEmpty(bucketName))
     {
         throw new ArgumentNullException("bucketName", "The bucketName cannot be null or the empty string!");
     }
     GetPreSignedUrlRequest request = new GetPreSignedUrlRequest();
     request.BucketName = bucketName;
     request.Expires = new DateTime(0x7e3, 12, 0x1f);
     request.Verb = HttpVerb.HEAD;
     HttpWebRequest request2 = WebRequest.Create(s3Client.GetPreSignedURL(request)) as HttpWebRequest;
     request2.Method = "HEAD";
     try
     {
         request2.GetResponse();
         flag = true;
     }
     catch (WebException exception)
     {
         using (HttpWebResponse response = exception.Response as HttpWebResponse)
         {
             if (response != null)
             {
                 HttpStatusCode statusCode = response.StatusCode;
                 return ((statusCode != HttpStatusCode.NotFound) && (statusCode != HttpStatusCode.BadRequest));
             }
             flag = false;
         }
     }
     return flag;
 }
开发者ID:pusp,项目名称:o2platform,代码行数:36,代码来源:AmazonS3Util.cs

示例2: DoesS3BucketExist

        /// <summary>
        /// Determines whether an S3 bucket exists or not.
        /// This is done by:
        /// 1. Creating a PreSigned Url for the bucket (with an expiry date at the end of this decade)
        /// 2. Making a HEAD request to the Url
        /// </summary>
        /// <param name="bucketName">The name of the bucket to check.</param>
        /// <param name="s3Client">The Amazon S3 Client to use for S3 specific operations.</param>
        /// <returns></returns>
        public static bool DoesS3BucketExist(string bucketName, AmazonS3 s3Client)
        {
            if (s3Client == null)
            {
                throw new ArgumentNullException("s3Client", "The s3Client cannot be null!");
            }

            if (String.IsNullOrEmpty(bucketName))
            {
                throw new ArgumentNullException("bucketName", "The bucketName cannot be null or the empty string!");
            }

            GetPreSignedUrlRequest request = new GetPreSignedUrlRequest();
            request.BucketName = bucketName;
            request.Expires = new DateTime(2019, 12, 31);
            request.Verb = HttpVerb.HEAD;
            request.Protocol = Protocol.HTTP;
            string url = s3Client.GetPreSignedURL(request);

            HttpWebRequest httpRequest = WebRequest.Create(url) as HttpWebRequest;
            httpRequest.Method = "HEAD";
            try
            {
                HttpWebResponse httpResponse = httpRequest.GetResponse() as HttpWebResponse;
                // If all went well, the bucket was found!
                return true;
            }
            catch (WebException we)
            {
                using (HttpWebResponse errorResponse = we.Response as HttpWebResponse)
                {
                    if (errorResponse != null)
                    {
                        HttpStatusCode code = errorResponse.StatusCode;
                        return code != HttpStatusCode.NotFound &&
                            code != HttpStatusCode.BadRequest;
                    }

                    // The Error Response is null which is indicative of either
                    // a bad request or some other problem
                    return false;
                }
            }
        }
开发者ID:writeameer,项目名称:AWSSDKForNet-extended,代码行数:53,代码来源:AmazonS3Util.cs

示例3: MakeUrl

        public static String MakeUrl(AmazonS3 s3Client, string filekey)
        {
            string preSignedURL = s3Client.GetPreSignedURL(new GetPreSignedUrlRequest()
            {
                BucketName = BUCKET_NAME,
                Key = filekey,
                Expires = System.DateTime.Now.AddYears(10)

            });

            return preSignedURL;
        }
开发者ID:xescrp,项目名称:breinstormin,代码行数:12,代码来源:S3Engine.cs


注:本文中的AmazonS3.GetPreSignedURL方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。