0

I want make thumbnail of pdffile when upload the file.

But, I don't wanna get stream from url after upload to storage(s3).

I wanna a get stream or buffer from request.

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 },
})

It is my trying.

Then, i got an error code.

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)

Thank you for your help.

곽대용
  • 399
  • 2
  • 3
  • 15
  • The error you found means you don't have GraphicsMagic/ImageMagick installed please download and install them first according to your platform. Also, do you want to save the original file to s3 or the thumbnail? – thammada.ts May 24 '20 at 18:36
  • yes. i wanna save tuhimbnail for pdf to s3 when upload pdf file. – 곽대용 May 25 '20 at 00:38

0 Answers0