我一直在努力從這個問題的答案位於這裏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
})
})
})