通过内容配置下载文件时,我不确定吗?

时间:2019-06-23 18:10:57

标签: node.js youtube youtube-api youtube-dl content-disposition

希望您一切都好。我在nodejs中是菜鸟,我想问一下如何使用内容配置强制下载文件时重命名文件

我正在尝试制作一个youtube下载网站,我可以下载该视频,但无法使用其原始名称进行下载。我想下载其原始文件名。

        var video = youtubedl('http://www.youtube.com/watch?v=90AiXO1pAiA',
      // Optional arguments passed to youtube-dl.
      //'--format=18'],
      // Additional options can be given for calling `child_process.execFile()`.
      { cwd: __dirname });

    // Will be called when the download starts.
    video.on('info', function(info) {
     // console.log('Download started');
      console.log('filename: ' + info._filename);
     // console.log('size: ' + info.size);
    //});

    //video.pipe(fs.createWriteStream('myvideo.mp4'));

res.header('Content-Disposition', 'attachment; filename='+info._filename);
youtubedl(URL,
  ['-x','--audio-format','mp3'],
  { cwd: __dirname }).pipe(res);
});
});

我希望输出的文件名应为“ Kanye West -Famous.mp3”,但我只会得到未定义格式的“ Kanye”。

0 个答案:

没有答案