问题描述
我目前正在构建一个Node.js应用程序,该应用程序最终将用于将某些文件格式转换为其他格式。 libreoffice-convert库正在完成大部分工作。
将本地文件路径传递到库时,我可以进行文件转换而没有任何问题,但是当我通过request()
抓取远程文件的内容并传递接收到的文件时,它似乎不起作用要转换为libreoffice的正文。
这是我现在拥有的相关代码:
request(fileUrl,{encoding: 'binary'},function(error,response,body) {
const ext = '.html';
libre.convert(body,ext,undefined,(err,done) => {
if (err) {
console.log(`Error converting file: ${err}`);
res.sendStatus(500);
} else {
console.log(done);
}
});
});
我可以看到,当我运行此命令时,libreoffice开始了转换,但是最终,我得到了这个错误:
Error: ENOENT: no such file or directory,open '/var/folders/j9/z_z85kh5501dbslrg53mpjsw0000gn/T/libreofficeConvert_-6529-x08o2o3peLMh/source..html
示例libreoffice-convert代码使用fs.readFileSync()
获取本地文件,但是鉴于我想从远程文件获取内容,因此我传递了{{1}中收到的body
}。
为确保request()
的内容正确,当在本地和远程调用相同的文件时,我将从body
接收到的结果与从fs.readFileSync()
接收到的结果进行了比较。似乎没有任何区别。
我是否缺少某些东西,或者libreoffice-convert库或libreoffice本身不支持此问题?
解决方法
libreoffice-convert 依赖于一些 linux 包,即 libreoffice-writer。 apt install libreoffice-writer
将解决您的问题。