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


C# PutObjectRequest.WithCannedACL方法代码示例

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


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

示例1: SaveImage

 /// <summary>
 /// Saves image to images.climbfind.com
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="filePath"></param>
 /// <param name="key"></param>
 public override void SaveImage(Stream stream, string filePath, string key)
 {
     try
     {
         using (var client = Amazon.AWSClientFactory.CreateAmazonS3Client(Stgs.AWSAccessKey, Stgs.AWSSecretKey, S3Config))
         {
             // simple object put
             PutObjectRequest request = new PutObjectRequest();
             request.WithBucketName("images.climbfind.com" + filePath);
             request.WithInputStream(stream);
             request.ContentType = "image/jpeg";
             request.Key = key;
             request.WithCannedACL(S3CannedACL.PublicRead);
             client.PutObject(request);
         }
     }
     catch (AmazonS3Exception amazonS3Exception)
     {
         if (amazonS3Exception.ErrorCode != null &&
             (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") ||
             amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
         {
             Console.WriteLine("Please check the provided AWS Credentials.");
             Console.WriteLine("If you haven't signed up for Amazon S3, please visit http://aws.amazon.com/s3");
         }
         else
         {
             Console.WriteLine("An error occurred with the message '{0}' when writing an object", amazonS3Exception.Message);
         }
     }
 }
开发者ID:jkresner,项目名称:Climbfind_v4_2011,代码行数:37,代码来源:AwsS3ImagePersister.cs

示例2: UploadToAmazon

        string UploadToAmazon(string fileName, Stream fileStream)
        {
            try
            {
                string uniqueKeyItemName = string.Format("{0}-{1}", keyName, fileName);
                PutObjectRequest request = new PutObjectRequest();
                request.WithInputStream(fileStream);
                request.WithBucketName(bucketName)
                    .WithKey(uniqueKeyItemName);
                request.WithMetaData("title", fileName);
                // Add a header to the request.
                //request.AddHeaders(AmazonS3Util.CreateHeaderEntry ("ContentType", contentType));

                S3CannedACL anonPolicy = S3CannedACL.PublicRead;
                request.WithCannedACL(anonPolicy);
                S3Response response = client.PutObject(request);

               //GetPreSignedUrlRequest publicUrlRequest = new GetPreSignedUrlRequest().WithBucketName(bucketName).WithKey( uniqueKeyItemName ).WithExpires(DateTime.Now.AddMonths(3) );
                //var urlResponse = client.GetPreSignedURL(publicUrlRequest);
                response.Dispose();
                var urlResponse = string.Format("https://s3.amazonaws.com/{0}/{1}", bucketName, uniqueKeyItemName );
                return urlResponse;
            }
            catch (AmazonS3Exception amazonS3Exception)
            {
                if (amazonS3Exception.ErrorCode != null &&
                    (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId")
                    ||
                    amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
                {
                    throw new Exception("Error - Invalid Credentials - please check the provided AWS Credentials", amazonS3Exception);
                }
                else
                {
                    throw new Exception(String.Format("Error occured when uploading media: {0}",amazonS3Exception.Message),amazonS3Exception);
                }
            }
        }
开发者ID:TellagoDevLabs,项目名称:CloudPoint,代码行数:38,代码来源:AmazonS3AssetStorageManager.cs

示例3: StoreFile

        private void StoreFile(string file, string key, string bucketName, bool publicRead, bool useGzip)
        {
            S3CannedACL acl = publicRead ? S3CannedACL.PublicRead : S3CannedACL.Private;

            var request = new PutObjectRequest();
            request
                .WithCannedACL(acl)
                .WithFilePath(file)
                .WithBucketName(bucketName)
                .WithKey(key);

            if (useGzip)
            {
                request.AddHeader("Content-Encoding", "gzip");
            }

            Client.PutObject(request);
        }
开发者ID:scalvert,项目名称:AWS-MSBuild-Task-Library,代码行数:18,代码来源:S3Helper.cs

示例4: UploadObject

        public void UploadObject(UploadRequest request)
        {
            CheckUri(request.Uri);

            try
            {
                var putRequest = new PutObjectRequest();
                using (var client = CreateAmazonS3Client())
                {
                    var absolutePath = HttpUtility.UrlDecode(request.Uri.AbsolutePath);
                    var key = absolutePath.TrimStart(Convert.ToChar("/"));

                    putRequest.WithBucketName(bucketName)
                        .WithKey(key)
                        .WithInputStream(request.InputStream);

                    if (accessControlEnabledGlobally && !request.IgnoreAccessControl)
                    {
                        putRequest.WithCannedACL(S3CannedACL.Private);
                    }
                    else
                    {
                        putRequest.WithCannedACL(S3CannedACL.PublicRead);
                    }

                    if (request.Headers != null && request.Headers.Count > 0)
                    {
                        putRequest.AddHeaders(request.Headers);
                    }

                    if (request.MetaData != null && request.MetaData.Count > 0)
                    {
                        putRequest.WithMetaData(request.MetaData);
                    }

                    putRequest.ContentType = MimeTypeUtility.DetermineContentType(request.Uri);

                    using (client.PutObject(putRequest))
                    {
                    }
                }
            }
            catch (Exception e)
            {
                throw new StorageException(string.Format("Failed to upload object with request {0}.", request), e);
            }
        }
开发者ID:navid60,项目名称:BetterCMS,代码行数:47,代码来源:AmazonS3StorageService.cs

示例5: CopyImage

        private static void CopyImage(object o)
        {
            UserData u = (UserData)o;

              try
              {
            string imagePath = String.Format("{0}\\L{1:00}\\R{2:x8}\\C{3:x8}.{4}", TileDirectory, u.Level, u.Row, u.Column, ContentType == "image/png" ? "png" : "jpg");

            if (File.Exists(imagePath))
            {
              byte[] file = File.ReadAllBytes(imagePath);

              PutObjectRequest putObjectRequest = new PutObjectRequest();
              putObjectRequest.WithBucketName(BucketName);
              putObjectRequest.WithKey(String.Format("{0}/{1}/{2}/{3}", MapName, u.Level, u.Row, u.Column));
              putObjectRequest.WithInputStream(new MemoryStream(file));
              putObjectRequest.WithContentType(ContentType);
              putObjectRequest.WithCannedACL(S3CannedACL.PublicRead);

              _s3Client.PutObject(putObjectRequest);
            }
              }
              catch (Exception ex)
              {
              }
              finally
              {
            _threadPool.Release();
              }
        }
开发者ID:agrc,项目名称:tile-etl,代码行数:30,代码来源:EtlToS3.cs

示例6: StoreFile

        private void StoreFile(string file, string key, string bucketName, bool publicRead)
        {
            S3CannedACL acl = publicRead ? S3CannedACL.PublicRead : S3CannedACL.Private;

            var request = new PutObjectRequest();
            request
                .WithCannedACL(acl)
                .WithFilePath(file)
                .WithBucketName(bucketName)
                .WithKey(key);

            Client.PutObject(request);
        }
开发者ID:saorsa,项目名称:AWS-MSBuild-Task-Library,代码行数:13,代码来源:S3Helper.cs

示例7: objectSerial

        public static void objectSerial(String filePath)
        {
            System.Console.WriteLine("\nhello,object!!");
            NameValueCollection appConfig = ConfigurationManager.AppSettings;

            AmazonS3 s3Client = AWSClientFactory.CreateAmazonS3Client(appConfig["AWSAccessKey"], appConfig["AWSSecretKey"]);
            String bucketName = "chttest3";
            String objectName = "hello";
            //String filePath = "D:\\Visual Studio Project\\TestNetSDK\\TestNetSDK\\pic.jpg";

            //PutBucket
            System.Console.WriteLine("PutBucket: {0}\n",bucketName);
            PutBucketResponse response = s3Client.PutBucket(new PutBucketRequest().WithBucketName(bucketName));

            //PutObject
            System.Console.WriteLine("PutObject!\n");
            PutObjectRequest request = new PutObjectRequest();
            request.WithBucketName(bucketName);
            request.WithKey(objectName);
            request.WithFilePath(filePath);
            PutObjectResponse PutResult = s3Client.PutObject(request);
            System.Console.WriteLine("Uploaded Object Etag: {0}\n", PutResult.ETag);

            //HeadObject
            System.Console.WriteLine("HeadObject!\n");
            GetObjectMetadataResponse HeadResult = s3Client.GetObjectMetadata(new GetObjectMetadataRequest().WithBucketName(bucketName).WithKey(objectName));
            System.Console.WriteLine("HeadObject: (1)ContentLength: {0} (2)ETag: {1}\n", HeadResult.ContentLength,HeadResult.ETag);

            //GetObject
            System.Console.WriteLine("GetObject!\n");
            GetObjectResponse GetResult =  s3Client.GetObject(new GetObjectRequest().WithBucketName(bucketName).WithKey(objectName).WithByteRange(1,15));

            Stream responseStream = GetResult.ResponseStream;
            StreamReader reader = new StreamReader(responseStream);
            System.Console.WriteLine("Get Object Content:\n {0}\n", reader.ReadToEnd());

            System.Console.WriteLine("Get Object ETag:\n {0}\n", GetResult.ETag);

            //CopyObject
            CopyObjectResponse CopyResult = s3Client.CopyObject(new CopyObjectRequest().WithSourceBucket(bucketName).WithSourceKey(objectName).WithDestinationBucket(bucketName).WithDestinationKey("hihi"));
            System.Console.WriteLine("CopyObject: ETag: {0} \n",CopyResult.ETag);

            //DeleteObject
            System.Console.WriteLine("Delete Object!\n");
            s3Client.DeleteObject(new DeleteObjectRequest().WithBucketName(bucketName).WithKey(objectName));
            s3Client.DeleteObject(new DeleteObjectRequest().WithBucketName(bucketName).WithKey("hihi")); //copied object

            //==============================jerry add ==============================
            System.Console.WriteLine("Jerry Add!\n");
            String objectName2 = "hello2";
            NameValueCollection nvc = new NameValueCollection();
            nvc.Add("A", "ABC");

            System.Console.WriteLine("PutObject!\n");
            PutObjectRequest request2 = new PutObjectRequest();
            request2.WithBucketName(bucketName);
            request2.WithKey(objectName2);
            request2.WithAutoCloseStream(true);
            request2.WithCannedACL(S3CannedACL.BucketOwnerFullControl);
            request2.WithContentBody("test");
            request2.WithContentType("test/xml");
            request2.WithGenerateChecksum(true);
            request2.WithMD5Digest("CY9rzUYh03PK3k6DJie09g==");

            request2.WithMetaData(nvc);
            request2.WithWebsiteRedirectLocation("http://hicloud.hinet.net/");
            PutObjectResponse PutResult2 = s3Client.PutObject(request2);
            System.Console.WriteLine("Uploaded Object Etag: {0}\n", PutResult2.ETag);

            System.Console.WriteLine("GetObject!\n");
            GetObjectRequest request3 = new GetObjectRequest();
            request3.WithBucketName(bucketName);
            request3.WithKey(objectName2);
            request3.WithByteRange(1, 2);
            DateTime datetime = DateTime.UtcNow;
            // 似乎不支援 datetime
            request3.WithModifiedSinceDate(datetime.AddHours(-1));
            request3.WithUnmodifiedSinceDate(datetime.AddHours(1));
            request3.WithETagToMatch(PutResult2.ETag);
            request3.WithETagToNotMatch("notMatch");
            GetObjectResponse GetResult2 = s3Client.GetObject(request3);
            Stream responseStream2 = GetResult2.ResponseStream;
            StreamReader reader2 = new StreamReader(responseStream2);
            System.Console.WriteLine("Get Object Content(es):\n {0}\n", reader2.ReadToEnd());
            System.Console.WriteLine("Get Object ETag:\n {0}\n", GetResult2.ETag);

            System.Console.WriteLine("HeadObject!\n");
            GetObjectMetadataRequest request4 = new GetObjectMetadataRequest();
            request4.WithBucketName(bucketName);
            request4.WithKey(objectName2);
            DateTime datetime2 = DateTime.UtcNow;
            // 似乎不支援 datetime
            request4.WithModifiedSinceDate(datetime2.AddHours(-1));
            request4.WithUnmodifiedSinceDate(datetime2.AddHours(1));
            request4.WithETagToMatch(PutResult2.ETag);
            request4.WithETagToNotMatch("notMatch");
            GetObjectMetadataResponse HeadResult2 = s3Client.GetObjectMetadata(request4);
            System.Console.WriteLine("HeadObject: (1)ContentLength: {0} (2)ETag: {1}\n", HeadResult2.ContentLength, HeadResult2.ETag);

            CopyObjectRequest request5 = new CopyObjectRequest();
//.........这里部分代码省略.........
开发者ID:kingbike,项目名称:NetSDK,代码行数:101,代码来源:Object.cs


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