0

Able to download the file .xls in Firefox browser using below script code.

window.open(/api/v1/test/id);

Able to download pdf,image extensions like jpg,jpeg etc.. Unable to download the .xls file in chrome browser using above script.

Please help to resolve this issue.

newtonash
  • 73
  • 2
  • 9

1 Answers1

0

Make sure that you set the Content-Type correctly at the server side.

For example, in Node for Excel 2007 and above .xlsx files

response.writeHead(200, {"Content-Type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});

Chrome is probably interpreting your content as application/zip

response.writeHead(200, {"Content-Type": "application/zip"});

Here is an example of an xlsx being served up in Chrome when accessing localhost:1215

  var http = require("http");
  fileSystem = require('fs'),
  path = require('path');
  var server = http.createServer(function(request, response) {

  var filePath = path.join(__dirname, '1775IronHorse.xlsx');
  var stat = fileSystem.statSync(filePath);
  response.writeHead(200, { "Content-Type": "application/vnd.openxmlformats-    officedocument.spreadsheetml.sheet",
                            'Content-Length': stat.size
                            });
  var readStream = fileSystem.createReadStream(filePath);
  readStream.pipe(response);
});

server.listen(1215);
console.log("Server is listening");

The file downloads correctly as an xlsx.

When I remove the Content-Type Header the file is interpreted as zip file by Chrome. Therefore, the solution is to add the Content-Type Header.

Source

forgetso
  • 1,566
  • 8
  • 23