Das Anfrageknotenmodul: https://github.com/request/request hat ein Beispiel, wo es nur die Antwort erhält und es dann in einen schreibbaren Dateistrom pipettiert. Was passiert, wenn ich einen variablen Dateinamen habe? Zum Beispiel, wenn der Link ein PNG oder ein JPG sein könnte? Wie pipere ich, nachdem ich die Antwort bekommen habe?Wie erstelle ich einen variablen Dateinamen mit der Anfrage nodejs Modul?
request.get('http://google.com/doodle.png').pipe(fs.createWriteStream('doodle.png'))
Zum Beispiel
request.get(fileURL)
.on('response', res => {
let resType = res.headers['content-type'];
//get the file name based on the content-type
})
.pipe(fs.createWriteStream(fileName); //should use the fileName created in the on('response') callback