Skip to content

convertTo fails after upgrade to 7.3.0 #335

Description

@mateuszbyczkowski

I started receiving following error in AWS Lambda in convertTo function after upgrading from 7.2.0 to 7.3.0 recently:

{"errorType":"Error","errorMessage":"Cannot generate PDF preview for ..docx file","stack":["Error: Cannot generate PDF preview for ..docx file"," at convertTo (/lambda/node_modules/@shelf/aws-lambda-libreoffice/lib/convert.js:46:11)"

My code in lambda handler.mjs:

  const { fileKey } = JSON.parse(message.body);
  if (!fileKey.endsWith('.docx')) {
    throw new Error(`File ${fileKey} is not a docx file`);
  }
  const getObjectResponse = await s3.send(
    new GetObjectCommand({
      Bucket: process.env.UPLOAD_BUCKET_NAME,
      Key: fileKey,
    }),
  );

  const docxFile = `document.docx`;
  const outputFilePath = `/tmp/document.pdf`;
  await pipeline(
    getObjectResponse.Body,
    fs.createWriteStream(`/tmp/${docxFile}`),
  );
  if (!canBeConvertedToPDF(docxFile)) {
    throw new Error(`File ${fileKey} cannot be converted to PDF`);
  }
  await convertTo(docxFile, 'pdf');

  await uploadFile(
    s3,
    outputFilePath,
    fileKey.replace('.docx', '.pdf'),
    getObjectResponse.Metadata,
  );
  fs.rmSync(`/tmp/${docxFile}`, { force: true });
  fs.rmSync(outputFilePath, { force: true });

Double dots before docx in an error message might be a good hint 🤔

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions