Skip to content

Instantly share code, notes, and snippets.

@dalian-spacekey
Created February 13, 2018 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalian-spacekey/3a4b73de20a4f02babd7ab30959544d6 to your computer and use it in GitHub Desktop.
Save dalian-spacekey/3a4b73de20a4f02babd7ab30959544d6 to your computer and use it in GitHub Desktop.
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