在我的metor / react应用程序中,我具有创建受保护的zip文件的服务器方法。

var image = fs.readFileSync(filePath);
var text = new Buffer(data);
var user_data = Meteor.user()._id;

mz.append(`${user_data}/data.json`, text, {
    password: password
});

mz.append(`${user_data}/national-id${path.extname(fileName)}`, image, {
    password: password
});

fs.writeFileSync(`${dir}/Cryptopass.zip`, new Buffer(mz.zip()));


现在如何将其发送给客户?

最佳答案

使用Express应该很简单:

const express = require('express');
var app = express();

app.route("/downloadzip").get(function(req,res){

    var mz = new Minizip();
    var image = fs.readFileSync(filePath);

    var text = new Buffer(data);
    var user_data = Meteor.user()._id;

    mz.append(`${user_data}/data.json`, text, {password: password});
    mz.append(`${user_data}/national-id${path.extname(fileName)}`, image, {password: password});

    res.type('zip').send(new Buffer(mz.zip()));
})

app.listen(8081);


要使用curl测试此路由:

curl http://localhost:8081/downloadImage > test.zip

10-04 21:30
查看更多