0

我想在上传文件时制作 pdffile 的缩略图。

但是,我不想在上传到存储(s3)后从 url 获取流。

我想从请求中获取流或缓冲区。

const upload = multer({
  storage: multerS3({
    s3: s3,
    bucket: storageConfig.s3.bucket,
    key: (req: any, file, cb) => {
      try {
        let body: any = []
        req.on('data', (data: any) => {
          body.push(data)
        })
        req.on('end', () => {
          body = Buffer.concat(body).toString()
          const buffer = Buffer.from(body, 'utf-8')
          gm(body)
            .thumb(
              200,
              200,
              path.join(__dirname, '/test.png'),
              80,
              (err, stdout, stderr, command) => {
                if (!err) {
                  console.log('clear')
                } else {
                  console.log('err')
                }
              }
            )
        })
        cb(null, workspaceId + '/files/' + fileId)
      } catch (e) {
        console.log('error ====')
        console.log(e)
      }
    },
    cacheControl: 'public, max-age=31536000',
    acl: 'public-read',
  }),
  limits: { fileSize: LIMIT_FILE_SIZE_PER_FILE },
})

这是我的尝试。

然后,我得到一个错误代码。

Error: Could not execute GraphicsMagick/ImageMagick: gm "identify" "-ping" "-format" "%wx%h" "-" this most likely means the gm/convert binaries can't be found
    at ChildProcess.<anonymous> (/Users/dany/workspace/paperly/projects/strum-server/node_modules/gm/lib/command.js:232:12)
    at ChildProcess.emit (events.js:315:20)
    at ChildProcess.EventEmitter.emit (domain.js:485:12)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:274:12)
    at onErrorNT (internal/child_process.js:468:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

谢谢您的帮助。

4

0 回答 0