本文整理汇总了C#中Amazon.S3.AmazonS3Client.PutObjectAsync方法的典型用法代码示例。如果您正苦于以下问题:C# AmazonS3Client.PutObjectAsync方法的具体用法?C# AmazonS3Client.PutObjectAsync怎么用?C# AmazonS3Client.PutObjectAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Amazon.S3.AmazonS3Client
的用法示例。
在下文中一共展示了AmazonS3Client.PutObjectAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UploadDataFileAsync
public async Task UploadDataFileAsync(string data, string storageKeyId, string storageSecret, string region)
{
var regionIdentifier = RegionEndpoint.GetBySystemName(region);
using (var client = new AmazonS3Client(storageKeyId, storageSecret, regionIdentifier))
{
try
{
var putRequest1 = new PutObjectRequest
{
BucketName = AwsBucketName,
Key = AwsBucketFileName,
ContentBody = data,
ContentType = "application/json"
};
await client.PutObjectAsync(putRequest1);
}
catch (AmazonS3Exception amazonS3Exception)
{
if (amazonS3Exception.ErrorCode != null &&
(amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") || amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
{
throw new SecurityException("Invalid Amazon S3 credentials - data was not uploaded.", amazonS3Exception);
}
throw new HttpRequestException("Unspecified error attempting to upload data: " + amazonS3Exception.Message, amazonS3Exception);
}
var response = await client.GetObjectAsync(AwsBucketName, AwsBucketFileName);
using (var reader = new StreamReader(response.ResponseStream))
{
Debug.WriteLine(await reader.ReadToEndAsync());
}
}
}
示例2: UploadItemAsync
private async Task<PutObjectResponse> UploadItemAsync(AmazonS3Client s3Client, string bucketName, string path, CancellationToken token)
{
using (var contentStream = _itemChange.CreateContentStream())
{
var request = new PutObjectRequest()
{
BucketName = bucketName,
Key = path + _itemChange.Item.Path,
ContentType = _itemChange.Item.ContentMetadata.ContentType,
InputStream = contentStream
};
return await s3Client.PutObjectAsync(request, token);
}
}
示例3: saveFile
public static void saveFile()
{
string accessKey = "*********************";
string secretKey = "******************************************";
AmazonS3Client s3 = new AmazonS3Client(accessKey, secretKey, Amazon.RegionEndpoint.USEast1);
var path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
var fileName = Path.Combine(path, "write.txt");
PutObjectRequest request = new PutObjectRequest{
BucketName = "calculatorkrao1",
Key = "EquationList",
FilePath = fileName,
};
System.Threading.Tasks.Task<PutObjectResponse> response = s3.PutObjectAsync(request);
}
示例4: CopyApplicationToBucketAsync
public async Task CopyApplicationToBucketAsync(string packagePath)
{
using (var s3Client = new AmazonS3Client(credentials, s3ConfigurationProvider.RegionEndpoint))
{
var putObjectRequest = new PutObjectRequest
{
BucketName = s3ConfigurationProvider.BucketName,
Key = s3ConfigurationProvider.FullKeyPath,
FilePath = packagePath
};
await s3Client.PutObjectAsync(putObjectRequest);
}
}