我一直在努力从这个问题的答案位于这里How to make a socket a stream? To connect https response to S3 after imagemagick。根据loganfsmyth的建议,我评论了req.end(image)行,但是当我尝试上传文件时,服务器只是超时。当我取消注释req.end(image)行时,我经历了类似的行为,但映像成功地上传了S3。有人能为我澄清哪种方式是正确的,如果是正确的取消注释req.end(图像)行什么是最好的方式发送一个响应浏览器,以防止它超时?奇怪的流行为node.js/knox
https.get(JSON.parse(queryResponse).data.url,function(res){
graphicsmagick(res)
.resize('50','50')
.stream(function (err, stdout, stderr) {
ws. = fs.createWriteStream(output)
i = []
stdout.on('data',function(data){
i.push(data)
})
stdout.on('close',function(){
var image = Buffer.concat(i)
var req = S3Client.put("new-file-name",{
'Content-Length' : image.length
,'Content-Type' : res.headers['content-type']
})
req.on('response',function(res){ //prepare 'response' callback from S3
if (200 == res.statusCode)
console.log('it worked')
})
//req.end(image) //send the content of the file and an end
})
})
})