I like to image proxy API. The API will download an image and return to clients.
However when browsing the API at http://localhost:8888/api/queue the image cannot be displayed.
I also tried to use curl to write to file:
curl http://localhost:8888/api/queue --output ./test21.png
This still did not work.
Could you please tell me if I have done anything wrong with my code?
router.get("/queue", (req, res) => {
axios({
method: 'GET',
url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/Image_created_with_a_mobile_phone.png/2560px-Image_created_with_a_mobile_phone.png',
responseType: 'arraybuffer'
}).then(function(response) {
var headers = {
'Content-Type': 'image/png'
};
res.writeHead(200, headers);
res.write(response.data, 'binary')
res.end();
return;
}).catch(function(error) {
res.send("error:" + error);
});
});