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


C# IAmazonS3.PutObject方法代码示例

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


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

示例1: Upload_object

 public static void Upload_object(string keyName, string filePath)
 {
     client = new AmazonS3Client("AKIAJWLLQBVBD4TTERPQ", "JOjpTd1crgwOmL99jlhs7qDYk5gpAlDEm2FxeWa6", Amazon.RegionEndpoint.USEast1);
     PutObjectRequest request = new PutObjectRequest()
     {
         BucketName = bucketName,
         Key = keyName,
         FilePath = filePath
     };
     PutObjectResponse response2 = client.PutObject(request);
 }
开发者ID:MazinZ,项目名称:hackNY,代码行数:11,代码来源:Program.cs

示例2: Upload

        public static string Upload(string pathToLocalFile, string awsAccessKey, string awsSecretKey, string bucketName, string s3Subfolder, string publicUriBase)
        {
            using (_client = AWSClientFactory.CreateAmazonS3Client(awsAccessKey, awsSecretKey, RegionEndpoint.EUWest1))
            {
                var name = Guid.NewGuid() + Path.GetExtension(pathToLocalFile);
                try
                {
                    var request = new PutObjectRequest
                    {
                        FilePath = pathToLocalFile,
                        BucketName = bucketName,
                        Key = s3Subfolder + "/" + name,
                        CannedACL = S3CannedACL.PublicRead
                    };

                    // TODO Handle response codes
                    // var response =
                    _client.PutObject(request);

                    // Return the Full URL for the uploaded image
                    return publicUriBase + "/" + name;
                }
                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);
                    }
                }
                catch (AmazonServiceException ase)
                {
                    Console.WriteLine("An Service exception error occurred with the message '{0}' when writing an object",
                            ase.Message);
                }
                return null;
            }
        }
开发者ID:gcmalloc,项目名称:content-manager,代码行数:46,代码来源:AWSS3Uploader.cs

示例3: PutObjectWithQuestionableKey

        static void PutObjectWithQuestionableKey(IAmazonS3 s3Client, string bucketName, string keyName)
        {
            const string testContent = "Some stuff to write as content";

            s3Client.PutObject(new PutObjectRequest
            {
                BucketName = bucketName,
                Key = keyName,
                ContentBody = testContent
            });

            var response = s3Client.GetObject(new GetObjectRequest
            {
                BucketName = bucketName,
                Key = keyName
            });

            using (var s = new StreamReader(response.ResponseStream))
            {
                var responseContent = s.ReadToEnd();
                Assert.AreEqual(testContent, responseContent);
            }
        }
开发者ID:wmatveyenko,项目名称:aws-sdk-net,代码行数:23,代码来源:KeyNameTests.cs

示例4: PutObjectWithQuestionableKey

        static void PutObjectWithQuestionableKey(IAmazonS3 s3Client, string bucketName, string keyName)
        {
            const string testContent = "Some stuff to write as content";

            s3Client.PutObject(new PutObjectRequest
            {
                BucketName = bucketName,
                Key = keyName,
                ContentBody = testContent
            });

            var response = s3Client.GetObject(new GetObjectRequest
            {
                BucketName = bucketName,
                Key = keyName
            });

            using (var s = new StreamReader(response.ResponseStream))
            {
                var responseContent = s.ReadToEnd();
                Assert.AreEqual(testContent, responseContent);
            }

            var presignedUrl = s3Client.GetPreSignedURL(new GetPreSignedUrlRequest
            {
                BucketName = bucketName,
                Key = keyName,
                Verb = HttpVerb.GET,
                Expires = DateTime.Now + TimeSpan.FromDays(5)
            });

            var httpRequest = HttpWebRequest.Create(presignedUrl);
            using(var httpResponse = httpRequest.GetResponse())
            using(var reader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var content = reader.ReadToEnd();
                Assert.AreEqual(testContent, content);
            }
        }
开发者ID:aws,项目名称:aws-sdk-net,代码行数:39,代码来源:KeyNameTests.cs

示例5: Upload

        public override void Upload(string container, string path, IUploadedFile file)
        {
            client = AWSClientFactory.CreateAmazonS3Client(ExtendedProperties["accessKey"], ExtendedProperties["secretKey"], RegionEndpoint.USEast1);
            String S3_KEY = path;

            PutObjectRequest request = new PutObjectRequest();
            request.BucketName = container;
            request.Key = S3_KEY;
            request.InputStream = file.Stream;
            client.PutObject(request);
        }
开发者ID:devaccelerate,项目名称:adapters-aws,代码行数:11,代码来源:AWSFileStorageManager.cs

示例6: PopulateBucket

        private void PopulateBucket(IAmazonS3 client, string bucketName)
        {
            client.PutObject(new PutObjectRequest()
            {
                BucketName = bucketName,
                Key = "Item",
                ContentBody = "Attempt number one"
            });

            for (int i = 0; i < 20; i++)
            {
                client.PutObject(new PutObjectRequest()
                {
                    BucketName = bucketName,
                    Key = "Item",
                    ContentBody = "Atempt " + i
                });
            }
        }
开发者ID:rajdotnet,项目名称:aws-sdk-net,代码行数:19,代码来源:BaseS3Samples.cs


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