In my node.js app, I'm using [gm (a graphicsmagick wrapper)][1] and [aws2js (amazon cli wrapper)][2]. The problem is that Amazon needs to know the content-length so that I can put the stream on S3.
I'm uploading an image to my app, read that file by creating a stream:
var fileStream=fs.createReadStream(file.path)
I pass that file to gm, resize it and then tell it to stream that file. I then want to put that stream to aws:
gm( fileStream, "some.png" ).
identify({bufferStream: true}, function(err, info) {
this.stream("png", function (err, stdout, stderr) {
if (err){console.log(err);cb(err);return;}
aws.S3.putStream(path, stdout, 'public-read', {'content-length': ?????, 'content-type': 'image/png'}, function (err, result) {
.....
}
});
});
});
The problem is that Amazon needs to know the content-length (its not the library) to put the stream. AWS doesn't support chunked streams.
Does anyone know how I could determine the content-length of a stream? Or would the only solution be to tmp write it to the disk, read the file as a stream and then put it to amazon with the content-length of the temp file?
[1]: https://github.com/aheckmann/gm
[2]: https://github.com/SaltwaterC/aws2js Did you ever figure this out? I'm trying to do exactly the same thing...
以上就是get a stream's content-length的详细内容,更多请关注web前端其它相关文章!