MeteorJS, метод сервера, jszip, docxtemplater - загрузить документ с клиента
Я определил следующий метод на стороне сервера MeteorJS:
'documents.generateDocx': function generateDocx()
{
//Load the docx file as a binary
//var content = fs.readFileSync(path.resolve('private/docx-tempaltes', 'simple.docx'), 'binary');
var content = Assets.getBinary('docx-templates/simple.docx');
var zip = new JSZip(content);
var doc = new Docxtemplater();
doc.loadZip(zip);
//set the templateVariables
doc.setData({
first_name: 'John',
last_name: 'Doe',
phone: '0652455478',
description: 'New Website'
});
try {
// render the document (replace all occurences of {first_name} by John, {last_name} by Doe, ...)
doc.render()
}
catch (error) {
var e = {
message: error.message,
name: error.name,
stack: error.stack,
properties: error.properties,
}
console.log(JSON.stringify({error: e}));
// The error thrown here contains additional information when logged with JSON.stringify (it contains a property object).
throw error;
}
var buf = doc.getZip().generate({type: 'nodebuffer'});
// buf is a nodejs buffer, you can either write it to a file or do anything else with it.
}
Я следую инструкциям и использую библиотеки jszip и docxtemplater для заполнения шаблона.docx. Теперь мне интересно, что было бы хорошим способом подать сгенерированный документ клиенту и немедленно начать загрузку сгенерированного документа.
Как обслуживать этот сгенерированный буфер для клиента.