2

I'm having trouble while downloading some images using node-fetch. This only happens on windows (osx works fine), and with specific urls.

At first, I thought it was related to node-fetch itself, but while stripping down my code to post an example to their issue page, I 'fixed' the problem:

This works on OSX, but only downloads a partial image on windows:

async function main2() {
  let url = 'https://www.chanel.com/images/q_auto,f_jpg,fl_lossy,dpr_2/w_1920/les-beiges-swatch-186587-8808323285022.jpg'

  response = await fetch(url);

  const file = fs.createWriteStream('test2.jpg');
  await new Promise((resolve, reject)=>{
    response.body.pipe(file);
    response.body.on('end', resolve);
    response.body.on('error', reject);
  })
  file.close();
}

This works on windows & OSX:

async function main() {
  let url = 'https://www.chanel.com/images/q_auto,f_jpg,fl_lossy,dpr_2/w_1920/les-beiges-swatch-186587-8808323285022.jpg'
  response = await fetch(url);

  const file = fs.createWriteStream('test.jpg');
  response.body.pipe(file);
  response.body.on('end', file.close);
}

My question(s) are, then:

  • Why do I get different results with these two snippets
  • Why do I get different results for different urls

Thanks!

bastien girschig
  • 663
  • 6
  • 26

0 Answers0