使用 expressjs,有没有办法让 mammoth 不使用路径?

Using expressjs, is there a way to use mammoth to not use a path?

如问题所述,有没有一种方法可以使用 mammoth 而不需要写入磁盘?我看到以下包裹:

https://www.npmjs.com/package/mammoth

var mammoth = require("mammoth");

mammoth.convertToHtml({path: "path/to/document.docx"})
    .then(function(result){
        var html = result.value; // The generated HTML
        var messages = result.messages; // Any messages, such as warnings during conversion
    })
    .done();

mammoth文档中,convertToHtml函数的第一个参数是inputinput是描述源文档的对象。在 node.js 上,他们支持 {path: path}{buffer: buffer}(或 {arrayBuffer: arrayBuffer})。

您可以将上传的文件转换为缓冲区,然后将缓冲区推送到 convertToHtml 函数。