1.直接下载 a标签加个download
2.asyne
async function downloadImage(imageSrc) {
const image = await fetch(imageSrc);
const imageBlog = await image.blob();
const imageURL = URL.createObjectURL(imageBlog);
const link = document.createElement("a");
link.href = imageURL;
link.download = "image file name here";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
let img = "https://xxx.com/1.png";
downloadImage(img);
3.nodejs
const fs = require("fs");
const https = require("https");
function saveImageToDisk(url, path) {
let fullUrl = url;
let localPath = fs.createWriteStream(path);
let request = https
.get(fullUrl, function (response) {
response.pipe(localPath);
})
.on("error", function (err) {
console.log(err);
});
}
let img = "https://i0.hdslb.com/bfs/article/c546f8b88ec17c0424573d1e7945689ae2de6072.png@942w_progressive.webp";
saveImageToDisk(img, "./uploads/" + Date.now() + ".webp");