aws-lambda-libreoffice icon indicating copy to clipboard operation
aws-lambda-libreoffice copied to clipboard

convertTo fails after upgrade to 7.3.0

Open mateuszbyczkowski opened this issue 8 months ago • 4 comments
trafficstars

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 🤔

mateuszbyczkowski avatar Mar 17 '25 08:03 mateuszbyczkowski

+1 We’ve experienced the same issue. Downgrading to 7.2.0 works.

danielsharvey avatar Apr 07 '25 07:04 danielsharvey

I am experiencing the same issue. Did you find any solution? Downgrading to 7.2.0 somehow did not work for me.

leeyongl5263 avatar May 06 '25 03:05 leeyongl5263

I am experiencing the same issue. Did you find any solution? Downgrading to 7.2.0 somehow did not work for me.

Check your package-lock.json (and package.json), if you have ^ in front of the version it will take latest available. In package.json you should have it like this: "@shelf/aws-lambda-libreoffice": "7.2.0"

Still waiting for a real solution 🙏🏻

mateuszbyczkowski avatar May 06 '25 07:05 mateuszbyczkowski

+1

simoa97 avatar Jun 09 '25 11:06 simoa97