当我的网站的用户点击.wav文件的链接时,是否可以强制打开Audacity?
我在我的网站上有这样的想法:
<a href="link/to/wav/on/server">Click to Listen this awesome track</a>我使用AngularJs作为前端,NodeJs作为后端服务器。wav位于NodeJs服务器的子目录中。
发布于 2016-06-08 23:47:28
你不能强迫计算机自己启动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);
});https://stackoverflow.com/questions/37705428
复制相似问题