"downloading image using axios" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "downloading image using axios" answered properly. Developers are finding an appropriate answer about downloading image using axios related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like downloading image using axios. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on downloading image using axios.
downloading image using axios
/* by Kindacode.com */
const fs = require('fs');
const path = require('path');
const axios = require('axios').default;
// fileUrl: the absolute url of the image or video you want to download
// downloadFolder: the path of the downloaded file on your machine
const downloadFile = async (fileUrl, downloadFolder) => {
// Get the file name
const fileName = path.basename(fileUrl);
// The path of the downloaded file on our machine
const localFilePath = path.resolve(__dirname, downloadFolder, fileName);
try {
const response = await axios({
method: 'GET',
url: fileUrl,
responseType: 'stream',
});
const w = response.data.pipe(fs.createWriteStream(localFilePath));
w.on('finish', () => {
console.log('Successfully downloaded file!');
});
} catch (err) {
throw new Error(err);
}
};
// Testing
const IMAGE_URL =
'https://www.kindacode.com/wp-content/uploads/2021/01/test.jpg';
downloadFile(IMAGE_URL, 'download');
const VIDEO_URL =
'https://www.kindacode.com/wp-content/uploads/2021/01/example.mp4';
downloadFile(VIDEO_URL, 'download');
Source: www.kindacode.com
All those coders who are working on the Whatever based application and are stuck on downloading image using axios can get a collection of related answers to their query. Programmers need to enter their query on downloading image using axios related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about downloading image using axios for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of downloading image using axios while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "downloading image using axios". Visit this developer's friendly online web community, CodeProZone, and get your queries like downloading image using axios resolved professionally and stay updated to the latest Whatever updates.