I'm trying to upload a PDF generated with chrome-aws-lambda in production and puppeteer in local. It works in local. But send the error of the title in production.
These are the params of presignedS3.
const pdf = await Helper.getPDFBuffer(html, options);
const merchantCod = params.merchantId;
const signedURLExpireSeconds = 60 * 10;
const rutaDocumento = params.folderMovement + "/"
const tipoDocumento = "facturaNro"
const extraRandomNumber = Math.floor(Math.random() * (10000 - 1)) + 1;;
let nroDocumento = params.nro
const presignedS3UrlPDF = await s3getSignedUrl("putObject", {
Bucket: BUCKET_NAME,
Key: "another/" + merchantCod + "/" + rutaDocumento + tipoDocumento + nroDocumento + "-" + extraRandomNumber+ ".pdf",
Expires: signedURLExpireSeconds,
ContentType: "application/pdf"
});
console.log("presignedS3UrlPDF123: ", presignedS3UrlPDF)
let resultUploadPDF = await uploadPDF(presignedS3UrlPDF, pdf);
This is the method**(Where is the error)** to upload the PDF
static async uploadPDF(presignedS3Url, pdf){
try {
let resultado = await axios.put(presignedS3Url,
Buffer.from(pdf)
, {
headers: {
'Content-Type': 'application/pdf'
}
});
console.log("Resultado Subida del PDF", resultado)
return resultado.statusText;
} catch (error) {
console.log("Mi error 1000", error)
console.log("El error 123",error.message)
return error;
}
}
And this is the method to get PDF Buffer
static getPDFBuffer = async (html, options) => {
let browser = null;
try {
const executablePath = process.env.IS_OFFLINE
? null
: await chromium.executablePath;
browser = await chromium.puppeteer.launch({
args: chromium.args,
executablePath,
});
const page = await browser.newPage();
const loaded = page.waitForNavigation({
waitUntil: "load",
});
await page.setContent(html);
await loaded;
return await page.pdf(options);
} catch (error) {
return error;
} finally {
if (browser !== null) {
await browser.close();
}
}
};