当前位置: 首页>>代码示例>>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;未经允许,请勿转载。