【问题标题】:cannot get this 'convert' cloud functions command to run无法运行此“转换”云功能命令
【发布时间】:2018-02-15 14:05:51
【问题描述】:

这个 firebase 函数应该在 /test/testfile.pdf 中获取一个 pdf,将其转换为灰色并保存在某处。我想在更复杂的过程中使用这个函数,但是 exec('convert') 真的没有帮助我。

问题是“exec”命令一直失败。在 shell 中,您在此处看到的确切命令行正在运行:

convert -colorspace GREY -density 300 test/testfile.pdf /tmp/out.pdf

日志中的错误是这样的:

{ ChildProcessError:命令失败:转换-colorspace GREY -density 300 test/testfile.pdf /tmp/out.pdf 转换:未定义图像`/tmp/out.pdf'@error/convert.c/ConvertImageCommand/3210 .在回调(/user_code/node_modules/child-process-promise/lib/index.js:33: 27) 在 ChildProcess.exithandler (child_process.js:205:5) 在 emitTwo (events.js:106:13) 在 ChildProcess.emit (events.js:191:7) 在可能关闭 (internal/child_process.js:920: 16) 在 Process.ChildProcess._handle.onexit (internal/child_process.js:230:5) 名称:'ChildProcessError',代码:1,childProcess:{ ChildProcess:{[Function:ChildProcess] super_:[Object]},fork :[函数],_forkChild:[函数],exec:[函数],execFile:[函数],spawn:[函数],spawnSync:[函数:spawnSync],execFileSync:[函数:execFileSync],execSync:[函数: execSync] }, stdout: '', stderr: 'convert: no images defined `/tmp/out.pdf\' @ error/convert.c/ConvertImageCommand/3210.\n' }

这是函数:

const functions = require('firebase-functions');
const rp = require('request-promise');
const request = require('request');
const baseURL = "https://www.google.com/cloudprint/"

const exec = require('child-process-promise').exec;
const mkdirp = require('mkdirp-promise');
const path = require('path');
const os = require('os');
const fs = require('fs');

exports.convertPDF = functions.https.onRequest((req, res) => {

  const tempLocalThumbFile = path.join(os.tmpdir(), "out.pdf");

  try {
   let tempLocalFile  = "test/testfile.pdf"
   exec('convert -colorspace GRAY -density 300 test/testfile.pdf '+tempLocalThumbFile).then((a) => {

      console.log('Conversion created at', tempLocalThumbFile);

  }, function (err) { 
      console.log(err)
  })
  } catch(err) {
      console.log(err)
  }
})

我很困。如何让这个转换在 Firebase Functions 中工作?

【问题讨论】:

  • 您的输出文件名 `/tmp/out.pdf\` 中似乎有一个反斜杠。带有尾随反斜杠的确切字符串在您的日志中出现两次。我想你必须弄清楚那是从哪里来的。
  • 可能与此相同的问题:superuser.com/questions/819277/… Cloud Functions 实例可能缺少转换 pdf 所需的 ghostscript。
  • 可能是。我试图找出是否是问题所在。

标签: firebase google-cloud-functions child-process imagemagick-convert


【解决方案1】:

实际上问题是@Nivco 所说的:Cloud Functions 缺少 ghostscript 包。已经有一个功能请求要求making ghostscript package available。当有新闻时,您可以转到链接并单击开始图标以获取电子邮件通知。

还有另一个StackoverFlow thread 提到了一种解决方法,包括自行获取 gs 二进制文件。

【讨论】:

    猜你喜欢
    • 2019-10-06
    • 1970-01-01
    • 1970-01-01
    • 2018-08-06
    • 2022-09-27
    • 1970-01-01
    • 1970-01-01
    • 2014-01-26
    • 1970-01-01
    相关资源
    最近更新 更多