十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
今天就跟大家聊聊有关使用Node.js怎么批量下载图片,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
创新互联主营兴化网站建设的网络公司,主营网站建设方案,成都APP应用开发,兴化h5小程序制作搭建,兴化网站营销推广欢迎兴化等地区企业咨询首先要获取到图片链接:
const img = [ "/file/tupian/20230213/7732.jpg", "/file/tupian/20230213/7733.jpg", "/file/tupian/20230213/7734.jpg", "/file/tupian/20230213/7735.jpg", "/file/tupian/20230213/7736.jpg", "/file/tupian/20230213/7737.jpg", "/file/tupian/20230213/7738.jpg", "/file/tupian/20230213/7739.jpg", "/file/tupian/20230213/7740.jpg", "/file/tupian/20230213/7741.jpg", "/file/tupian/20230213/7742.jpg", "/file/tupian/20230213/7743.jpg", "/file/tupian/20230213/7744.jpg", "/file/tupian/20230213/7745.jpg", "/file/tupian/20230213/7746.jpg", "/file/tupian/20230213/7747.jpg", "/file/tupian/20230213/7748.jpg", "/file/tupian/20230213/7749.jpg", "/file/tupian/20230213/7750.jpg", "/file/tupian/20230213/7751.jpg", "/file/tupian/20230213/7752.jpg", "/file/tupian/20230213/7753.jpg", "/file/tupian/20230213/7754.jpg", "/file/tupian/20230213/7755.jpg", "/file/tupian/20230213/7756.jpg", "/file/tupian/20230213/7757.jpg", "/file/tupian/20230213/7758.jpg", "/file/tupian/20230213/7759.jpg", "/file/tupian/20230213/7760.jpg", "/file/tupian/20230213/7761.jpg", "/file/tupian/20230213/7762.jpg", "/file/tupian/20230213/7763.jpg", "/file/tupian/20230213/7764.jpg", "/file/tupian/20230213/7765.jpg", "/file/tupian/20230213/7766.jpg", "/file/tupian/20230213/7767.jpg", "/file/tupian/20230213/7768.jpg", "/file/tupian/20230213/7769.jpg", "/file/tupian/20230213/7770.jpg", "/file/tupian/20230213/7771.jpg", "/file/tupian/20230213/7772.jpg", "/file/tupian/20230213/7774.jpg" ];
批量下载图片:
var fs = require('fs'); var request = require("request"); img.forEach(src => { var writeStream = fs.createWriteStream(src.split('/2019/08/')[1]); var readStream = request(src) readStream.pipe(writeStream); readStream.on('end', function() { console.log('文件下载成功'); }); readStream.on('error', function() { console.log(1); // console.log("错误信息:" + err) }) writeStream.on("finish", function() { console.log("文件写入成功"); writeStream.end(); }); });
看完上述内容,你们对使用Node.js怎么批量下载图片有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。