當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。