node.js - S3 fails to unzip uploaded file -
i'm following this example
// load stream var fs = require('fs'), zlib = require('zlib'); var body = fs.createreadstream('bigfile').pipe(zlib.creategzip()); // upload stream var s3obj = new aws.s3({params: {bucket: 'mybucket', key: 'mykey'}}); s3obj.upload({body: body}, function(err, data) { if (err) console.log("an error occurred", err); console.log("uploaded file at", data.location); }) and "works" in expected, except file arrives on s3 compressed , stays way.
as far can tell there's no auto facility unzip on s3, so, if intention upload publicly available image or video (or else end user meant consume) solution appears leave uploaded file unzipped so...
// load stream var fs = require('fs'), zlib = require('zlib'); var body = fs.createreadstream('bigfile');//.pipe(zlib.creategzip()); <-- removing zipping part // upload stream var s3obj = new aws.s3({params: {bucket: 'mybucket', key: 'mykey'}}); s3obj.upload({body: body}, function(err, data) { if (err) console.log("an error occurred", err); console.log("uploaded file at", data.location); }) i'm curious if i'm doing wrong , if there automatic way have s3 recognize file arriving zipped , unzip it?
the way works s3 has way of knowing file gziped without bit of help. need set metadata on file when uploading telling s3 it's gzipped. right thing set.
you need set content-encoding: gzip , content-type: <<your file type>> in object metadata when uploading.
later edit: found these explains how cloudfront, same: http://docs.aws.amazon.com/amazoncloudfront/latest/developerguide/servingcompressedfiles.html#compresseds3
http://www.cameronstokes.com/2011/07/20/compressed-content-amazon-s3-and-cloudfront/
however note per this blogpost s3 serve file gzipped , rely on browser unzip it. works fine in many cases blogger notes fail in curl (since curl have no idea gzipped file). if intention upload file raw consumption user best bet skip gzipping , upload file in uncompressed state.
Comments
Post a Comment