0

I have got problem with setting path to download files in this case for images. I download image from URL with blob construction like this:

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 = 'asd.png'
    document.body.appendChild(link)
    link.click()
    document.body.removeChild(link)
} 

Then i catch a download signal on main.js like this:

session.defaultSession.on("will-download", (event, item, webContents) => {
        item.setSavePath( /local_dir/ + item.getFilename());
    }) 

When i log getFilename() i have got correct filename what i want, silent also too works because i havent got a window to locate directory of download, but when i look into directory it is empty.

Thanks for help.

  • Does your code really say `/local_dir/`? That isn't a path but rather a regular expression and thus saving wouldn't work. You'd have to make a string out of it. – Alexander Leithner Feb 19 '22 at 12:57

1 Answers1

0

So i have done this by adding __dirname const to path

item.setSavePath(__dirname + '\\photos\\' + item.getFilename());
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 19 '22 at 22:02