Asp.net mvc 4 如何使用asp.net mvc在amazon aws s3 bucket中保存和获取纯文本数据?
我正在尝试使用ASP.NET MVC在AWS S3存储桶中保存纯文本数据,您能帮助实现此目的吗???在ASP.NET MVC中保存并获取AWS S3存储桶中的数据:-Asp.net mvc 4 如何使用asp.net mvc在amazon aws s3 bucket中保存和获取纯文本数据?,asp.net-mvc-4,amazon-s3,Asp.net Mvc 4,Amazon S3,我正在尝试使用ASP.NET MVC在AWS S3存储桶中保存纯文本数据,您能帮助实现此目的吗???在ASP.NET MVC中保存并获取AWS S3存储桶中的数据:- try { var credentials = new Amazon.Runtime.BasicAWSCredentials(awsKey, awsSecretKey); AmazonS3Client client
try
{
var credentials = new Amazon.Runtime.BasicAWSCredentials(awsKey, awsSecretKey);
AmazonS3Client client = new AmazonS3Client(credentials, RegionEndpoint.APSouth1);
GetObjectRequest request = new GetObjectRequest()
{
BucketName = bucketName,
Key = "1"// because we pass 1 as unique key while save
//data at the s3 bucket
};
using (GetObjectResponse response = client.GetObject(request))
{
StreamReader reader = new
StreamReader(response.ResponseStream);
vccEncryptedData = reader.ReadToEnd();
}
}
catch (AmazonS3Exception)
{
throw;
}
在amazon s3存储桶中保存纯文本数据
1.首先,您需要在aws上创建一个bucket,而不是
2.您需要您的aws凭据,如a)aws密钥b)aws密钥c)区域
//在aws保存数据的代码//注意,您可能会遇到访问被拒绝错误。要删除此项,请检查AWS帐户并授予//读写权限
需要从NuGet包添加名称空间
using Amazon;
using Amazon.S3;
using Amazon.S3.Model;
var credentials = new Amazon.Runtime.BasicAWSCredentials(awsKey, awsSecretKey);
try`
{
AmazonS3Client client = new AmazonS3Client(credentials, RegionEndpoint.APSouth1);
// simple object put
PutObjectRequest request = new PutObjectRequest()
{
ContentBody = "put your plain text here",
ContentType = "text/plain",
BucketName = "put your bucket name here",
Key = "1"
//put unique key to uniquly idenitify your data
// you can pass here any data with unique id like primary key
//in db
};
PutObjectResponse response = client.PutObject(request);
}
catch(exception ex)
{
//
}
现在转到您的AWS帐户,检查您可以在AWS s3 bucket中获得名称为“1”的数据的bucket。注意:-如果您有任何其他问题,请在这里问我一个问题,我将尝试解决它
从AWS s3存储桶获取数据:-
try
{
var credentials = new Amazon.Runtime.BasicAWSCredentials(awsKey, awsSecretKey);
AmazonS3Client client = new AmazonS3Client(credentials, RegionEndpoint.APSouth1);
GetObjectRequest request = new GetObjectRequest()
{
BucketName = bucketName,
Key = "1"// because we pass 1 as unique key while save
//data at the s3 bucket
};
using (GetObjectResponse response = client.GetObject(request))
{
StreamReader reader = new
StreamReader(response.ResponseStream);
vccEncryptedData = reader.ReadToEnd();
}
}
catch (AmazonS3Exception)
{
throw;
}