下载一个epub

时间:2016-11-04 13:45:14

标签: node.js epub

我正在尝试下载我在服务器上生成的epub。我正在使用NodeJS(和角度)。

在Node中我这样做:

var fs = require('fs');
fs.readFile('book.epub', function(err, content) {
    if (err) {
        response.writeHead(400, {'Content-type':'text/html'});
        response.end("No such file");
    }
    else {
        response.setHeader('content-type', 'application/epub+zip');
        response.end(content);
    }
});

在前端我这样做:

var binaryData = [];
binaryData.push(file);                        
var a = document.createElement('a');
a.href = window.URL.createObjectURL(new Blob(binaryData, {type: "application/epub+zip"}));
a.download = "book.zip";
a.click();

当我打开下载的zip时,它会创建一个新的zip。我缺少什么?

0 个答案:

没有答案