国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

How do Express and request proxy remote images?
習(xí)慣沉默
習(xí)慣沉默 2017-05-16 13:45:34
0
3
729

Use Node's Express combined with request to proxy remote images, but the content returned is different from the content of the original image. It is garbled, but the chaos is inconsistent.
Key code:

var FurionImgHandler = function (req, res) {
    var url = req.url.split('/fimg/')[1];
    var options = {
        url: url
    };

    function callback (error, response, body) {
        if (!error && response.statusCode === 200) {
            var contentType = response.headers['content-type'];
            response.setEncoding('binary');
            res.set('Content-Type', contentType);
            res.send(body);
        }
    }

    request.get(options, callback);
};

Original picture:

Pictures returned after proxying:

習(xí)慣沉默
習(xí)慣沉默

reply all(3)
習(xí)慣沉默

Just add encoding: null and that’s it

var options = {
    url: url,
    encoding: null
};
阿神

It should be the passed Blob object. Try converting it.

大家講道理

If the image does not require storage or other operations, can't it be passed directly to the response through the pipe?

http.get(options, (response) => {
    response.pipe(res);
})

soonfy

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template