2014-11-18 5 views
0

현재 실행 중이지만 이미지를 출력 할 수 없습니다. 현재 실행 중이지만 브라우저에서 이미지를 출력하지 않습니다. 인코딩과 관련이 있습니까?출력 원격 PNG 출력

http.createServer(function (req, res) { 
    var options = { 
    host: 'www.website.com', 
    path: '/'+req.url 
    }; 

    http.request(options, function(response) { 
    var str = ''; 

    response.on('data', function (chunk) { 
    str += chunk; 
    }); 

    response.on('end', function() { 
    res.writeHead(200, {'Content-Type': 'image/png;'}); 
    res.end(str); 
    }); 
    }).end(); 
}).listen(8000); 

답변

0

버퍼가 아닌 문자열로 처리하기 때문에 UTF-8에 맞지 않는 데이터가 손상됩니다. 어떤 이미지가 많이 있습니다.

당신은 아마 두 개의 스트림 연결하려면 :

res.writeHead(200, {'Content-Type': 'image/png'}); response.pipe(res);