奇怪的流行为node.js/knox

奇怪的流行为node.js/knox,node.js,amazon-web-services,amazon-s3,imagemagick,knox-amazon-s3-client,Node.js,Amazon Web Services,Amazon S3,Imagemagick,Knox Amazon S3 Client,我一直在研究这个问题的答案。根据loganfsmyth建议,我对req.end(image)行进行了注释,但是当我尝试上载文件时,服务器只是超时。当我取消注释req.end(image)行时,我会经历类似的行为,唯一的例外是镜像成功地上传到了S3。有人能为我澄清一下哪种方式是正确的吗?如果取消注释请求结束(图像)行是正确的,那么向浏览器发送响应以防止超时的最佳方式是什么 https.get(JSON.parse(queryResponse).data.url,function(res){

我一直在研究这个问题的答案。根据loganfsmyth建议,我对req.end(image)行进行了注释,但是当我尝试上载文件时,服务器只是超时。当我取消注释req.end(image)行时,我会经历类似的行为,唯一的例外是镜像成功地上传到了S3。有人能为我澄清一下哪种方式是正确的吗?如果取消注释请求结束(图像)行是正确的,那么向浏览器发送响应以防止超时的最佳方式是什么

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
      })
  })
})

基本上,页面被请求了两次,这导致图像由于favicon而被覆盖

在您链接到的问题中,用户使用的是
putStream
,因此调用
req.end()
是不正确的,但是在您的情况下,您直接使用
put
,因此需要调用
req.end()
。否则,如果将其注释掉,则除了长度之外,您永远不会实际使用
图像
值,因此您永远不会发送图像数据

如果看不到实际运行此代码的服务器处理程序,很难判断,但是您需要(可选)返回一些响应,然后
.end()
也返回到浏览器的实际连接,否则它将设置在那里等待

如果你有这样的东西

http.createServer(function(req, browserResponse){

  // Other code.

  req.on('response',function(s3res){  //prepare 'response' callback from S3
      if (200 == s3res.statusCode) console.log('it worked')


      // Close the response. You also pass it data to send to the browser.
      browserResponse.end();
  })

  // Other code.
});