WIP Download Images + Invoice Tables
This commit is contained in:
24
download-images.js
Normal file
24
download-images.js
Normal file
@@ -0,0 +1,24 @@
|
||||
var JSZip = require("jszip");
|
||||
const axios = require("axios"); // to get the images
|
||||
require("dotenv").config();
|
||||
|
||||
module.exports.downloadImages = async function(req, res) {
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
console.log("[IMAGES] Incoming Images to Download", req.body);
|
||||
}
|
||||
const zip = new JSZip();
|
||||
//res.json({ success: true });
|
||||
req.body.images.forEach(i => {
|
||||
axios.get(i).then(r => zip.file(r));
|
||||
// const buffer = await response.buffer();
|
||||
// zip.file(file, buffer);
|
||||
});
|
||||
// // Set the name of the zip file in the download
|
||||
res.setHeader("Content-Type", "application/zip");
|
||||
|
||||
zip.generateAsync({ type: "nodebuffer" }).then(
|
||||
function(content) {
|
||||
res.send(content);
|
||||
}.bind(res)
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user