code: 'ETIMEDOUT', host: 'miro.medium.com', hostname: 'miro.medium.com', method: 'GET', path: '/v2/resize:fit:1200/1*zPt6so-N8gphr7Kyw6OA1w.jpeg', protocol: 'https:', url: 'https://miro.medium.com/v2/resize:fit:1200/1*zPt6so-N8gphr7Kyw6OA1w.jpeg'
Getting this error while downloading image using AXIOS npm package in node.js.
The code used is provided below:
let inputImageUrl = "https://miro.medium.com/v2/resize:fit:1200/1%2AzPt6so-N8gphr7Kyw6OA1w.jpeg";
// Decode the URL to remove percent-encoded characters
const decodedUrl = decodeURIComponent(inputImageUrl);
// Set a User-Agent header to mimic a browser request
const userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.0.0 Safari/537.36";
axios
.get(decodedUrl, {
headers: {
"User-Agent": userAgent
},
responseType: "stream",
timeout: 10000 // Increase the timeout to 10 seconds (adjust as needed)
})
.then((response) => {
// Handle the response
})
.catch((err) => {
console.error(err);
});
I have decoded the input image url and used the decoded url to download but still issue occured, the error is added above.
The correct url is as follows "https://miro.medium.com/v2/resize:fit:1200/1%2AzPt6so-N8gphr7Kyw6OA1w.jpeg"
I have also tried SuperAgent, download, node-downloader-helper packages to download this image, but it didn't work.
There is no problem with the code; you can ensure that with another image URL.
It seems Miro has limited external access to the assets.