我在页面上有链接,单击时我想要打开外部docx文件.不幸的是,fs.readFile只读取本地路径. 我试过了 app.get('/getfile', function (req, res) { var externalURL = 'http://www.examplesite.com/example.docx'; // var exte
我试过了
app.get('/getfile', function (req, res) {
var externalURL = 'http://www.examplesite.com/example.docx';
// var externalURL = req.query.external;
fs.readFile(externalURL, function(err, data) {
var fileData = new Buffer(data).toString('base64');
res.send(fileData);
});
});
试试这个:
const http = require("http");
const file = fs.createWriteStream("file.docx");
http.get("http://www.example.com/test.docx", response => {
response.pipe(file);
});
