Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use AmazonS3(.NET/C#)
using System.IO;
using System.Threading.Tasks;
using Amazon;
using Amazon.S3;
using Amazon.S3.Model;
namespace UseAmazonS3
{
class Program
{
static async Task Main(string[] args)
{
var client = new AmazonS3Client(
"*AccessKey*",
"*SecretAccessKey*",
new AmazonS3Config
{
RegionEndpoint = RegionEndpoint.APNortheast1
});
// Upload
var response = await client.GetObjectAsync(new GetObjectRequest
{
BucketName = "*BucketName*",
Key = "*KeyName*"
});
var stream = new MemoryStream();
response.ResponseStream.CopyTo(stream);
File.WriteAllBytes(@"c:\temp\*Keyname*", stream.ToArray());
// Download
await client.PutObjectAsync(new PutObjectRequest
{
BucketName = "*BucketName*",
Key = "*KeyName*",
InputStream = new MemoryStream(File.ReadAllBytes(@"c:\temp\*KeyName*"))
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.