Created
December 31, 2016 18:05
-
-
Save hclewk/71deef1113662c09b65c9384e5c186a1 to your computer and use it in GitHub Desktop.
Upload GZipped String to S3 - Fire and Forget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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