Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

electron 如何下载图片并保存?

请问如何下载图片 https://cdn.ostack.cn/v-5f0a9217/global/img/user-64.png
并保存到本地

// 请问如何获取下载文件并保存
fs.writeFileSync('1.png', data, {
encoding: 'binary'
})

我尝试

const res = await got('https://cdn.ostack.cn/v-5f0a9217/global/img/user-64.png', {
    responseType: 'buffer'
});
// 走不到下一步
fs.writeFileSync('1.png', res.body, {
encoding: 'binary'
})

但是这样并不能下载图片, https://github.com/sindresorhus/got/issues/899


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

有没有设置网络代理或者防火墙,跟代理有关系的话,用net 模块试一下


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...