[英]what's wrong with my node.js stream code?
我的服務器中有一個m4a音頻文件,我想在設備上獲取它。 我可以獲得帶有此代碼的文件,但無法在手機和PC上播放它。
我認為該文件傳輸不正確。 你能給我一些建議嗎? (我的服務器上沒有錯誤或警告消息)
app.get('/upload/:file',function(req,res){
console.log('download');
var filename = req.params.file;
var path = './disk/'+filename;
var stat = fs.statSync(path);
res.writeHead(200, {
'Content-Type': 'audio/m4a',
'Content-Length': stat.size
});
var readStream = fs.createReadStream(path);
readStream.setEncoding('utf8');
readStream.pipe(res);
console.log('done');
})
刪除此行:
readStream.setEncoding('utf8');
並且二進制數據將未經修改地傳遞(此行當前被解釋為utf-8文本數據)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.