无法使用jquery从chrome浏览器下载.xls文件
Unable to download the .xls file from chrome browser using jquery
可以使用下面的脚本代码在Firefox浏览器中下载。xls文件。
window.open(/api/v1/test/id);
能够下载pdf,图像扩展如jpg,jpeg等。使用上述脚本无法在chrome浏览器中下载。xls文件。
请帮忙解决这个问题
确保在服务器端正确设置Content-Type
例如,在Node For Excel 2007及以上版本中。xlsx文件
response.writeHead(200, {"Content-Type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});
Chrome 可能将您的内容解释为application/zip
response.writeHead(200, {"Content-Type": "application/zip"});
下面是一个xlsx在Chrome浏览器中被服务时访问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");
文件以xlsx格式正确下载。
当我删除Content-Type头文件被Chrome解释为zip文件。因此,解决方案是添加Content-Type报头。
源相关文章:
- 通过Android Chrome浏览器下载文件
- 强制web浏览器下载整个页面内容
- 当浏览器下载所需的文件时,GIF 在初始屏幕中缓慢制作动画
- 响应式设计:这个Javascript会导致浏览器下载两个图像吗?
- 浏览器下载 JSON 结果,而不是传递回脚本
- 如何支持从所有浏览器下载mp3
- 拖动文件以在火狐浏览器下载
- 使用javascript获取浏览器下载路径
- 如何将内存流调用到浏览器下载
- 在加载网站时访问浏览器下载的资产
- 在html5中,我可以强制浏览器下载音频文件I'我在用
- 使用wcf从服务器获取文件并在客户端浏览器下载
- 如何强制浏览器下载并缓存当前未显示在页面上的图像
- 如何让web浏览器下载存储在JavaScript字符串中的文件
- 浏览器下载状态
- 无法使用jquery从chrome浏览器下载.xls文件
- 提示浏览器下载对话框
- 使用浏览器下载队列中的多个文件
- 强制浏览器下载Html页面,而不是呈现它
- 是否有可能在浏览器下载页面时显示Twitter引导进度条?