Skip to content

Instantly share code, notes, and snippets.

@hclewk
Created December 31, 2016 18:05
Show Gist options
  • Save hclewk/71deef1113662c09b65c9384e5c186a1 to your computer and use it in GitHub Desktop.
Save hclewk/71deef1113662c09b65c9384e5c186a1 to your computer and use it in GitHub Desktop.
Upload GZipped String to S3 - Fire and Forget
AmazonS3Client client = new AmazonS3Client(RegionEndpoint.USWest2);
MemoryStream mem = new MemoryStream();
using (GZipStream gz = new GZipStream(mem, CompressionLevel.Optimal, true))
{
var b = Encoding.UTF8.GetBytes(json);
gz.Write(b, 0, b.Length);
gz.Flush();
}
var request = new Amazon.S3.Model.PutObjectRequest()
{
BucketName = "mybucket",
CannedACL = S3CannedACL.Private,
ContentType = "application/json",
InputStream = mem,
Key = "dir/filename.json.gz",
};
request.Headers["Content-Encoding"] = "gzip";
var ignore = client.PutObjectAsync(request)
.ContinueWith(c =>
{
//TODO: handle upload error
client.Dispose();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment