Home > Blockchain >  saveImageToDisk nodejs
saveImageToDisk nodejs

Time:11-24

I wanted to know how to make saveimagetodisk write the files as you go and not all in one block at once

Impossible to do folder manipulation operations after saveImageTodisk because the files are not yet created

CodePudding user response:

You could do this using a fileWriteStream with the built in fs module and whatever modules you use for fetching data here i have used http

const http = require('http')
const URL = `https://pinymedia.web.app/hashtag.png` //Replace with your image
const file = fs.createWriteStream("./file.jpg");
const request = http.get(URL, function(response) {
   response.pipe(file);

   // after download completed close filestream
   file.on("finish", () => {
       file.close();
       console.log("Download Completed");
   });
});

Hope this helps

CodePudding user response:

unfortunately it still doesn't work

function saveImageToDisk(url, path) {
  let fullUrl = url;
  let localPath = fs.createWriteStream(path);

  let request = https.get(fullUrl, function (response) {
    // console.log(response);
    response.pipe(localPath);
  })

  // after download completed close filestream
  localPath.on("finish", () => {
    localPath.close();
    console.log("Download Completed");
});

console.log

./uploads/1669221377695.jpg
./uploads/1669221377695.jpg
./uploads/1669221377736.jpg
./uploads/1669221377736.jpg
./uploads/1669221377738.jpg
./uploads/1669221377738.jpg
./uploads/1669221377739.jpg
./uploads/1669221377739.jpg
./uploads/1669221377740.jpg
./uploads/1669221377740.jpg
./uploads/1669221377742.jpg
./uploads/1669221377742.jpg
./uploads/1669221377743.jpg
./uploads/1669221377743.jpg
./uploads/1669221377744.jpg
./uploads/1669221377744.jpg
./uploads/1669221377745.jpg
./uploads/1669221377745.jpg
./uploads/1669221377746.jpg
./uploads/1669221377746.jpg
./uploads/1669221377747.jpg
./uploads/1669221377747.jpg
./uploads/1669221377748.jpg
./uploads/1669221377748.jpg
./uploads/1669221377749.jpg
./uploads/1669221377749.jpg
./uploads/1669221377750.jpg
./uploads/1669221377750.jpg
./uploads/1669221377752.jpg
./uploads/1669221377752.jpg
./uploads/1669221377753.jpg
./uploads/1669221377753.jpg
./uploads/1669221377754.jpg
./uploads/1669221377754.jpg
./uploads/1669221377755.jpg
./uploads/1669221377755.jpg
./uploads/1669221377756.jpg
./uploads/1669221377756.jpg
./uploads/1669221377757.jpg
./uploads/1669221377757.jpg
./uploads/1669221377758.jpg
./uploads/1669221377758.jpg
./uploads/1669221377759.jpg
./uploads/1669221377759.jpg
./uploads/1669221377760.jpg
./uploads/1669221377760.jpg
./uploads/1669221377761.jpg
./uploads/1669221377761.jpg
./uploads/1669221377762.jpg
./uploads/1669221377762.jpg
./uploads/1669221377763.jpg
./uploads/1669221377763.jpg
./uploads/1669221377764.jpg
./uploads/1669221377764.jpg
./uploads/1669221377765.jpg
./uploads/1669221377765.jpg
./uploads/1669221377766.jpg
./uploads/1669221377766.jpg
./uploads/1669221377766.jpg
./uploads/1669221377766.jpg
vide
vide
./uploads/1669221377787.jpg
./uploads/1669221377787.jpg
./uploads/1669221377788.jpg
./uploads/1669221377788.jpg
./uploads/1669221377790.jpg
./uploads/1669221377790.jpg
./uploads/1669221377791.jpg
./uploads/1669221377791.jpg
./uploads/1669221377792.jpg
./uploads/1669221377792.jpg
./uploads/1669221377792.jpg
./uploads/1669221377792.jpg
./uploads/1669221377793.jpg
./uploads/1669221377793.jpg
./uploads/1669221377794.jpg
./uploads/1669221377794.jpg
./uploads/1669221377795.jpg
./uploads/1669221377795.jpg
./uploads/1669221377796.jpg
./uploads/1669221377796.jpg
./uploads/1669221377796.jpg
./uploads/1669221377796.jpg
./uploads/1669221377797.jpg
./uploads/1669221377797.jpg
./uploads/1669221377798.jpg
./uploads/1669221377798.jpg
./uploads/1669221377799.jpg
./uploads/1669221377799.jpg
./uploads/1669221377800.jpg
./uploads/1669221377800.jpg
./uploads/1669221377800.jpg
./uploads/1669221377800.jpg
./uploads/1669221377801.jpg
./uploads/1669221377801.jpg
./uploads/1669221377802.jpg
./uploads/1669221377802.jpg
./uploads/1669221377804.jpg
./uploads/1669221377804.jpg
./uploads/1669221377804.jpg
./uploads/1669221377804.jpg
./uploads/1669221377805.jpg
./uploads/1669221377805.jpg
./uploads/1669221377806.jpg
./uploads/1669221377806.jpg
./uploads/1669221377807.jpg
./uploads/1669221377807.jpg
./uploads/1669221377808.jpg
./uploads/1669221377808.jpg
./uploads/1669221377809.jpg
./uploads/1669221377809.jpg
./uploads/1669221377810.jpg
./uploads/1669221377810.jpg
./uploads/1669221377811.jpg
./uploads/1669221377811.jpg
./uploads/1669221377811.jpg
./uploads/1669221377811.jpg
./uploads/1669221377812.jpg
./uploads/1669221377812.jpg
./uploads/1669221377813.jpg
./uploads/1669221377813.jpg
vide
vide
vide
vide
vide
./uploads/1669221377824.jpg
./uploads/1669221377824.jpg
./uploads/1669221377826.jpg
./uploads/1669221377826.jpg
./uploads/1669221377826.jpg
./uploads/1669221377826.jpg
./uploads/1669221377827.jpg
./uploads/1669221377827.jpg
./uploads/1669221377828.jpg
./uploads/1669221377828.jpg
./uploads/1669221377831.jpg
./uploads/1669221377831.jpg
./uploads/1669221377833.jpg
./uploads/1669221377833.jpg
./uploads/1669221377834.jpg
./uploads/1669221377834.jpg
./uploads/1669221377835.jpg
./uploads/1669221377835.jpg
./uploads/1669221377836.jpg
./uploads/1669221377836.jpg
./uploads/1669221377837.jpg
./uploads/1669221377837.jpg
./uploads/1669221377838.jpg
./uploads/1669221377838.jpg
./uploads/1669221377838.jpg
./uploads/1669221377838.jpg
./uploads/1669221377839.jpg
./uploads/1669221377839.jpg
./uploads/1669221377840.jpg
./uploads/1669221377840.jpg
./uploads/1669221377841.jpg
./uploads/1669221377841.jpg
./uploads/1669221377841.jpg
./uploads/1669221377841.jpg
./uploads/1669221377842.jpg
./uploads/1669221377842.jpg
./uploads/1669221377843.jpg
./uploads/1669221377843.jpg
./uploads/1669221377844.jpg
./uploads/1669221377844.jpg
./uploads/1669221377845.jpg
./uploads/1669221377845.jpg
./uploads/1669221377845.jpg
./uploads/1669221377845.jpg
./uploads/1669221377846.jpg
./uploads/1669221377846.jpg
./uploads/1669221377847.jpg
./uploads/1669221377847.jpg
./uploads/1669221377848.jpg
./uploads/1669221377848.jpg
./uploads/1669221377849.jpg
./uploads/1669221377849.jpg
./uploads/1669221377849.jpg
./uploads/1669221377849.jpg
./uploads/1669221377850.jpg
./uploads/1669221377850.jpg
./uploads/1669221377851.jpg
./uploads/1669221377851.jpg
./uploads/1669221377852.jpg
./uploads/1669221377852.jpg
vide
vide
./uploads/1669221377853.jpg
./uploads/1669221377853.jpg
./uploads/1669221377853.jpg
./uploads/1669221377853.jpg
./uploads/1669221377854.jpg
./uploads/1669221377854.jpg
./uploads/1669221377855.jpg
./uploads/1669221377855.jpg
./uploads/1669221377856.jpg
./uploads/1669221377856.jpg
./uploads/1669221377857.jpg
./uploads/1669221377857.jpg
./uploads/1669221377857.jpg
./uploads/1669221377857.jpg
./uploads/1669221377858.jpg
./uploads/1669221377858.jpg
./uploads/1669221377859.jpg
./uploads/1669221377859.jpg
./uploads/1669221377860.jpg
./uploads/1669221377860.jpg
./uploads/1669221377860.jpg
./uploads/1669221377860.jpg
./uploads/1669221377861.jpg
./uploads/1669221377861.jpg
./uploads/1669221377862.jpg
./uploads/1669221377862.jpg
./uploads/1669221377863.jpg
./uploads/1669221377863.jpg
./uploads/1669221377864.jpg
./uploads/1669221377864.jpg
./uploads/1669221377865.jpg
./uploads/1669221377865.jpg
./uploads/1669221377866.jpg
./uploads/1669221377866.jpg
./uploads/1669221377867.jpg
./uploads/1669221377867.jpg
./uploads/1669221377868.jpg
./uploads/1669221377868.jpg
./uploads/1669221377868.jpg
./uploads/1669221377868.jpg
./uploads/1669221377869.jpg
./uploads/1669221377869.jpg
./uploads/1669221377870.jpg
./uploads/1669221377870.jpg
./uploads/1669221377871.jpg
./uploads/1669221377871.jpg
./uploads/1669221377871.jpg
./uploads/1669221377871.jpg
./uploads/1669221377872.jpg
./uploads/1669221377872.jpg
./uploads/1669221377873.jpg
./uploads/1669221377873.jpg
./uploads/1669221377874.jpg
./uploads/1669221377874.jpg
./uploads/1669221377874.jpg
./uploads/1669221377874.jpg
./uploads/1669221377875.jpg
./uploads/1669221377875.jpg
./uploads/1669221377876.jpg
./uploads/1669221377876.jpg
vide
vide
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
Download Completed
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s
attendre 1s

CodePudding user response:

enter image description here here is a small excerpt of the code and the files that I manage to generate. I run the javascript alone without starting the server

  • Related