我想使用来自 Azure 存储的 nodeJS 将图像从 URL 下载到服务器,但遇到错误。当我获取最小记录 300 到 500 时,该函数工作正常。每当我调用 node.js 服务器获取大量记录的所有数据时,我都会收到此错误。这是我的功能。如何处理 ETIMEDOUT 错误?
return new Promise((ok, notOk) => {
try {
const file = fs.createWriteStream(saveWhere);
const sendReq = request.get(url);
sendReq.on('response', (response) => {
if (response.statusCode !== 200) {
console.log('error downloading file', url, 'not valid response code');
ok();
}
sendReq.pipe(file);
});
file.on('finish', () => file.close(ok));
sendReq.on('error', (err) => {
console.log('error downloading file +++ 1', err);
// fs.unlink(saveWhere);
fs.unlink(saveWhere, function (err) {
if (err) {
console.log(" ======= unlink cb==",err)
}
})
return notOk(err);
});
} catch (e) {
console.log("this is error +++ ", e);
return not();
}
});
错误
Error: read ETIMEDOUT
at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20) {
errno: -110,
code: 'ETIMEDOUT',
syscall: 'read'
}
error downloading file +++ 1 Error: getaddrinfo EAI_AGAIN soneparseaapacidprodstg.blob.core.windows.net
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26) {
errno: -3001,
code: 'EAI_AGAIN',
syscall: 'getaddrinfo',
hostname: 'soneparseaapacidprodstg.blob.core.windows.net'
}
error downloading file +++ 1 Error: read ETIMEDOUT
at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20) {
errno: -110,
code: 'ETIMEDOUT',
syscall: 'read'
}