當前位置: 首頁>>代碼示例>>C#>>正文


C# AmazonS3.PutBucket方法代碼示例

本文整理匯總了C#中AmazonS3.PutBucket方法的典型用法代碼示例。如果您正苦於以下問題:C# AmazonS3.PutBucket方法的具體用法?C# AmazonS3.PutBucket怎麽用?C# AmazonS3.PutBucket使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在AmazonS3的用法示例。


在下文中一共展示了AmazonS3.PutBucket方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CheckForBucket

 public static void CheckForBucket(string itemKey, AmazonS3 s3Client)
 {
     if (HttpContext.Current.User.Identity.IsAuthenticated)
     {
         string userBucketName = String.Format(Settings.Default.BucketNameFormat, HttpContext.Current.User.Identity.Name, itemKey);
         using (ListBucketsResponse listBucketsResponse = s3Client.ListBuckets())
         {
             S3Bucket bucket = listBucketsResponse.Buckets.FirstOrDefault(b => b.BucketName == userBucketName);
             if (bucket == null)
             {
                 PutBucketRequest putBucketRequest = new PutBucketRequest()
                     .WithBucketName(userBucketName);
                 PutBucketResponse putBucketResponse = s3Client.PutBucket(putBucketRequest);
                 putBucketResponse.Dispose();
             }
         }
     }
 }
開發者ID:bernardoleary,項目名稱:MyBigBro,代碼行數:18,代碼來源:BucketHelper.cs

示例2: AddBucket

        /// <summary>
        /// Add Bucket
        /// </summary>
        /// <param name="client">Client</param>
        /// <param name="bucket">Bucket</param>
        public void AddBucket(AmazonS3 client, string bucket)
        {
            if (string.IsNullOrWhiteSpace(this.from))
            {
                this.from = bucket;

                this.fromClient = client;
            }
            else
            {
                this.to = bucket;

                this.toClient = client;

                var request = new PutBucketRequest()
                {
                    BucketName = bucket,
                };

                using (var response = client.PutBucket(request))
                {
                }
            }
        }
開發者ID:dineshkummarc,項目名稱:A-Trak,代碼行數:29,代碼來源:StorageFactory.cs

示例3: AddImageToAmazon

        private bool AddImageToAmazon(Coupon coupon, HttpPostedFile File, string ext)
        {
            string count = "";
            string keyname = "";
            //ext = ".jpg";
            //try
            //{
                string accessKeyID = WebConfigurationManager.AppSettings["AWSAccessKey"];
                string secretAccessKeyID = WebConfigurationManager.AppSettings["AWSSecretKey"];

                AmazonS3Config s3Config = new AmazonS3Config();
                s3Config.UseSecureStringForAwsSecretKey = false;

                client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKeyID, secretAccessKeyID, s3Config);
                //count += "1";
                ICouponDAO couponDAO = _factoryDAO.GetCouponDAO();
                Byte[] imgByte = new byte[0];
                //count += "2";
                //Create byte Array with file len
                imgByte = new Byte[File.ContentLength];
                //count += "3";
                //force the control to load data in array
                File.InputStream.Read(imgByte, 0, File.ContentLength);
                //count += "4";
                //count += ext;
                //count += _merchantname;
                //count += _couponID.ToString();
                //count += File.FileName;
                //count += File.FileName.Substring(0, File.FileName.IndexOf("."));
                //count += ":";
                //count += string.Format("{0}{1}", _couponID.ToString(), ext);
                keyname = string.Format("{0}/{1}", _merchantname, File.FileName.Replace(File.FileName.Substring(0, File.FileName.IndexOf(".")), string.Format("{0}{1}", _couponID.ToString(), ext)));
                //keyname = string.Format("{0}/{1}", _merchantname, File.FileName.Replace(File.FileName.Substring(0, File.FileName.IndexOf(".")), _couponID.ToString()));
                count += keyname;
                /*try
                {
                    //first try deleting old item if applicable
                    DeleteObjectRequest delete_request = new DeleteObjectRequest();
                    delete_request.WithBucketName("gfck").WithKey(string.Format("coupon/{0}", keyname));
                    S3Response delete_response = client.DeleteObject(delete_request);
                    delete_response.Dispose();
                }
                catch (Exception ex)
                {
                    _log.ErrorFormat("Error trying to delete object from bucket: {0} with exception {1}", keyname, ex.Message);
                }*/
                string BUCKET_NAME = String.Format("gfck/coupon/{0}", _merchantname);
                try
                {
                    //add the bucket just in case not already there.
                    //PutObjectRequest request1 = new PutObjectRequest();
                    PutBucketRequest req = new PutBucketRequest();
                    req.WithBucketName(BUCKET_NAME);
                    //count += "6";
                    //request1.WithBucketName("gfck").WithContentType(File.ContentType).WithCannedACL(S3CannedACL.PublicReadWrite).WithKey(BUCKET_NAME);
                    //S3Response response = client.PutObject(request1);
                    //response.Dispose();
                    client.PutBucket(req);
                }
                catch (Exception ex)
                {
                    _log.DebugFormat("This bucket already exists: {0} with exception {1}", BUCKET_NAME, ex.Message);
                }

                //count += "5";
                PutObjectRequest request = new PutObjectRequest();
                //count += "6";
                request.WithBucketName("gfck").WithContentType(File.ContentType).WithCannedACL(S3CannedACL.PublicRead).WithKey(string.Format("coupon/{0}", keyname)).WithInputStream(File.InputStream);
                count += "here";
                S3Response response = client.PutObject(request);
                count += "7";
                response.Dispose();
                count += "8";
                if (ext == "")
                {
                    coupon.Image = keyname;
                }
                else
                {
                    coupon.BottomAdvertisement = keyname;
                }
                count += "9";

                return couponDAO.UpdateCoupon(coupon);
            /*}
            catch (Exception ex)
            {
                _log.ErrorFormat("Exception Occurred: Exception={0}", ex.Message);
                lblError.Text = String.Format("Error with coupon image. {0} {1} {2}", count, keyName, ex.Message);
                lblError.Visible = true;
                lblAddSuccessfull.Visible = false;
                lblEditSuccessfull.Visible = false;
                return false;
            }*/
        }
開發者ID:jedgoski,項目名稱:GFCK,代碼行數:95,代碼來源:Action.aspx.cs

示例4: SetUp

        public void SetUp()
        {
            _client = AWSClientFactory.CreateAmazonS3Client(Access_Key_ID, Secret_Access_Key);

            //A pre-requisite for testing S3 Objects. Ensure that we create two temporary buckets to test the Objects.
            //One for normal operations, other for Copying to the destination bucket.
            //A. Create the bucket.
            bool hasCallbackArrived = false;

            S3ResponseEventHandler<object, ResponseEventArgs> handler = null;
            handler = delegate(object sender, ResponseEventArgs args)
            {
                IS3Response result = args.Response;
                //Unhook from event.
                _client.OnS3Response -= handler;
                hasCallbackArrived = true;
            };
            _client.OnS3Response += handler;

            PutBucketRequest request = new PutBucketRequest() { BucketName = _bucketName };
            _client.PutBucket(request);

            EnqueueConditional(() => hasCallbackArrived);

            //B. Create the destination bucket as well.
            bool hasDestinationCallbackArrived = false;
            S3ResponseEventHandler<object, ResponseEventArgs> destinationHandler = null;
            destinationHandler = delegate(object sender, ResponseEventArgs args)
            {
                IS3Response result = args.Response;
                //Unhook from event.
                _client.OnS3Response -= destinationHandler;
                hasDestinationCallbackArrived = true;
            };
            _client.OnS3Response += destinationHandler;

            PutBucketRequest requestDestination = new PutBucketRequest() { BucketName = _bucketNameDestination };
            _client.PutBucket(requestDestination);

            EnqueueConditional(() => hasDestinationCallbackArrived);

            EnqueueTestComplete();
        }
開發者ID:svcgoo1,項目名稱:AWS-SDK-for-WP,代碼行數:43,代碼來源:AmazonS3Client_Tests.cs

示例5: CreateBucket

 private void CreateBucket(AmazonS3 client)
 {
     PutBucketRequest request = new PutBucketRequest();
     request.BucketName = this.BucketName;
     client.PutBucket(request);
 }
開發者ID:oo00spy00oo,項目名稱:SharedTerminals,代碼行數:6,代碼來源:AmazonOptionPanel.cs

示例6: SetupBucket

 private void SetupBucket(AmazonS3 client)
 {
     client.PutBucket(new PutBucketRequest {BucketName = BucketName});
 }
開發者ID:sonbua,項目名稱:Mantle,代碼行數:4,代碼來源:AwsS3StorageClient.cs

示例7: CreateBucket

        private static void CreateBucket(AmazonS3 client, string bucketname)
        {
            Console.Out.WriteLine("Checking S3 bucket with name " + bucketname);

            ListBucketsResponse response = client.ListBuckets();

            bool found = false;
            foreach (S3Bucket bucket in response.Buckets)
            {
                if (bucket.BucketName == bucketname)
                {
                    Console.Out.WriteLine("   Bucket found will not create it.");
                    found = true;
                    break;
                }
            }

            if (found == false)
            {
                Console.Out.WriteLine("   Bucket not found will create it.");

                client.PutBucket(new PutBucketRequest().WithBucketName(bucketname));

                Console.Out.WriteLine("Created S3 bucket with name " + bucketname);
            }
        }
開發者ID:xescrp,項目名稱:breinstormin,代碼行數:26,代碼來源:S3Engine.cs

示例8: CreateBucket

 private static void CreateBucket(AmazonS3 s3Client, string bucket)
 {
     var putBucketRequest = new PutBucketRequest { BucketName = bucket };
       s3Client.PutBucket(putBucketRequest);
 }
開發者ID:nrazon,項目名稱:S3Emulator,代碼行數:5,代碼來源:Program.cs


注:本文中的AmazonS3.PutBucket方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。