vendredi 23 janvier 2015

what's wrong with my node.js stream code?

I have a m4a audio file in my server, and I want to get it on my device. I can get a file with this code, but I cannot play it on my phone and PC.


I think that the file was transferred incorrectly. Can you give me some advice? (there are no error or warning messages on my server)



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');


})


Aucun commentaire:

Enregistrer un commentaire