A Nodejs module for downloading image to disk from a given URL
A Node module for downloading image to disk from a given URL
npm install --save image-downloader
options.url
(see usage bellow)options.url
or not. Set to false
to haveoptions.dest
without a file extension for example. (default: true
){}
)For advanced options, see Node.js http.request()
's options documentation
declare module download {
image(options: Options): Promise<{ filename: string }>;
}
Download to a directory and save with the original filename
const download = require('image-downloader')
const options = {
url: 'http://someurl.com/image.jpg',
dest: '/path/to/dest' // will be saved to /path/to/dest/image.jpg
}
download.image(options)
.then(({ filename }) => {
console.log('Saved to', filename) // saved to /path/to/dest/image.jpg
})
.catch((err) => console.error(err))
Download to a directory and save with an another filename
const download = require('image-downloader')
options = {
url: 'http://someurl.com/image2.jpg',
dest: '/path/to/dest/photo.jpg' // will be saved to /path/to/dest/photo.jpg
}
download.image(options)
.then(({ filename }) => {
console.log('Saved to', filename) // saved to /path/to/dest/photo.jpg
})
.catch((err) => console.error(err))
Download with another filename without extension
const download = require('image-downloader')
options = {
url: 'http://someurl.com/image3.jpg',
dest: '/path/to/dest/photo', // will be saved to /path/to/dest/photo
extractFilename: false
}
download.image(options)
.then(({ filename }) => {
console.log('Saved to', filename) // saved to /path/to/dest/photo
})
.catch((err) => console.error(err))
Under the MIT license. See LICENSE file for more details.