如何使用aws .net c #sdk将文件上传到aws s3存储桶

时间:2018-03-20 07:28:56

标签: .net amazon-web-services amazon-s3 c#-3.0

 var client = new AmazonS3Client(Amazon.RegionEndpoint.USEast2);

        try
        {
            PutObjectRequest putRequest = new PutObjectRequest
            {
                BucketName = bucketName,
                Key = keyName,
                ContentBody = filePath,
                ContentType = "text/plain"
            };

            PutObjectResponse response = client.PutObject(putRequest);
        }

我想使用此代码将文件上传到s3存储桶 这是我得到的错误。

Error   CS0122  'AmazonS3Client.PutObject(PutObjectRequest)' is inaccessible due to its protection level    

1 个答案:

答案 0 :(得分:2)

我猜这是.NET Core。在.NET Core中,只有异步版本是公共的,以匹配底层HttpClient在.NET Standard 1.3中支持的内容,这是AWS SDK针对基于.NET Core项目的目标。在您的情况下,您需要致电client.PutObjectAsync