I found this solution, but for me doesn't work.
Hi, I'm trying to upload a file from server side (that i just created using fs.writefile) , and I would like to get the file Side(Angular js). I can get the data from server , but my Stream.pipe doesnt launch a download.
here is a sample of the code from backend
params.fs.writeFile(pathFile,response, function (err) {
if (err) {
throw err;
}
res.writeHead(200,{
'Content-Type': 'text/xml',
'Content-Disposition': 'attachment; filename=' + fileName
});
var fileStream = params.fs.createReadStream(pathFile);
console.log(fileStream);
fileStream.pipe(res);`
and here frontend `Class.getXmlFile(id).then(function(xmlFile){ console.log(xmlFile);`:
Thanks.
So I am going to write how I fixed this: After make my function in server I am sending already my file to front end, so I only need a normal request instead XmlHttpRequest that is waiting for a promise(response) to ask my file in server:
Here both codes:
params.fs.writeFile(pathFile,response, function (err) {
if (err) {
throw err;
}
res.writeHead(200,{
'Content-Type': 'text/xml',
'Content-Disposition': 'attachment; filename=' + fileName
});
var fileStream = params.fs.createReadStream(pathFile);
console.log(fileStream);
fileStream.pipe(res);
Client Side: window.open(path/to/backend)