-
-
Save AliAryanTech/982dee98c423f38e3e7c7e5bdef9eec5 to your computer and use it in GitHub Desktop.
Proper way of downloading a large file using NodeJS and Axios (NodeJS 10+)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as stream from 'stream'; | |
import { promisify } from 'util'; | |
const finished = promisify(stream.finished); | |
export async function downloadFile(fileUrl: string, outputLocationPath: string): Promise<any> { | |
const writer = createWriteStream(outputLocationPath); | |
return Axios({ | |
method: 'get', | |
url: fileUrl, | |
responseType: 'stream', | |
}).then(async response => { | |
response.data.pipe(writer); | |
return await finished(writer); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment