0

当我的网站的用户单击指向 .wav 文件的链接时,是否可以强制打开 Audacity?

我的网站上有这样的想法:

<a href="link/to/wav/on/server">Click to Listen this awesome track</a>

我使用 AngularJs 作为前端,NodeJs 作为后端服务器。wav 位于 NodeJs 服务器的子目录中。

4

1 回答 1

0

您不能强制计算机自行启动 Audacity,这取决于用户的偏好。您可以做的是提示将文件下载到客户端,浏览器可能会建议他通过处理文件扩展名的应用程序列表打开它或下载它。你可以这样实现:

var mime = require('mime'),
    fs = require('fs');

app.get('link/to/wav/on/server', function(req, res){

  var file = 'filelocationOnTheServer.wav';

  res.setHeader('Content-disposition', 'attachment; filename=nameYouWantToGiveit.wav');
  res.setHeader('Content-type', 'audio/wav'); // This will make the browser to use the most appropriate app according to it's preference.
  // res.setHeader('Content-type', 'application/octet-stream'); // This will never match to anything and will push the browser to ask the user what to do and to download it.

  fs.createReadStream(file).pipe(res);
});
于 2016-06-08T15:47:28.423 回答