4

I've seen alot of NodeJs question about downloading file from given URL. But my issue here is that, the image URL is an auto download type, where when pasted on browser, it won't show the image on the browser but will auto download that said image immediately.

This code works on the direct image URL, and i can see the downloaded file on the folder.

request.head(targetURL, (err, res, body) => {
        request(targetURL)
            .pipe(fs.createWriteStream(path.join(__dirname, '..', 'assets', 'download.jpg')))
            .on('close', () => {
               console.log('Done!')
            });
    });

But when i try to use auto download link, i see 1kb size image that is empty. I cannot get the supposed image from the auto download link.

Did i do anything wrong in here?

Ps: Just to add here, this link is not a direct URL to the image.. its a link that triggers the download of that said image. In this case, i want to know how would NodeJs handles with it.

Fred A
  • 1,602
  • 1
  • 24
  • 41
  • 1
    Check this post, you will get your answer [https://stackoverflow.com/questions/11944932/how-to-download-a-file-with-node-js-without-using-third-party-libraries](https://stackoverflow.com/questions/11944932/how-to-download-a-file-with-node-js-without-using-third-party-libraries) – turivishal Jun 05 '20 at 07:35
  • Tried @turivishal ... i checked that thread, and i tried to follow it (using https instead of http coz im dealing with https URL). The downloaded image is still 1kb.. the image is supposed to be few MB size. – Fred A Jun 05 '20 at 07:46
  • Is it possible for you to share the image-url? – eol Jun 05 '20 at 08:21
  • One example would be a link to the PDF version of a shared Google Doc., e.g., https://docs.google.com/document/d//export?format=pdf Links of this kind automatically trigger a download of the requested PDF without providing direct access to the PDF the way that direct PDF URLs ending in `.pdf` do. – Jacob Fredericksen Oct 03 '22 at 05:10

0 Answers0