Код «Ошибка: для операции не задан ввод» в nodejs, работающем из AWS lambda
Я чисто новичок в nodejs. Я пытаюсь экспортировать pdf в docx, используя PDF API, доступный в службах Adobe API. У меня есть немного кода в Интернете, чтобы добиться этого от nodejs (Python здесь не подходит). У меня есть файл в AWS S3, нужно экспортировать файл в docx. Я сделал небольшие изменения в коде. Когда я пытаюсь запустить это . Он выдает исключение: «Обнаружено исключение при выполнении операции-2. Ошибка: для операции не задан вход». Нужна помощь или совет, чтобы преодолеть это.
/*
* Copyright 2019 Adobe
* All Rights Reserved.
*
* NOTICE: Adobe permits you to use, modify, and distribute this file in
* accordance with the terms of the Adobe license agreement accompanying
* it. If you have received this file from a source other than Adobe,
* then your use, modification, or distribution of it requires the prior
* written permission of Adobe.
*/
// Lambda handler code //
console.log('Loading function');
exports.handler = async (event, context) => {
console.log('Loading function');
const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');
// Start reading the file from s3//
const aws = require('aws-sdk');
//const s3 = new aws.S3({ apiVersion: '2006-03-01' });
const bucket = 'translation-bucket-qa-v1';
const key = 'TranslationPipeline/input_pdf_img/Gas_bill_sample.pdf'
const filename = 'Gas_bill_sample.pdf'
/*
const params = {
Bucket: bucket,
Key: key,
};
try {
const { ContentType } = await s3.getObject(params).promise();
console.log('CONTENT TYPE:', ContentType);
return ContentType;
} catch (err) {
console.log(err);
const message = 'Error getting object ${key} from bucket ${bucket}. Make sure they exist and your bucket is in the same region as this function.';
console.log(message);
throw new Error(message);
}*/
//Reading the file ends here !!!!///
/**
* This sample illustrates how to export a PDF file to a Word (DOCX) file
* <p>
* Refer to README.md for instructions on how to run the samples.
*/
try {
// Initial setup, create credentials instance.
const credentials = PDFServicesSdk.Credentials
.serviceAccountCredentialsBuilder()
.fromFile("pdfservices-api-credentials.json")
.build();
//Create an ExecutionContext using credentials and create a new operation instance.
const executionContext = PDFServicesSdk.ExecutionContext.create(credentials),
exportPDF = PDFServicesSdk.ExportPDF,
exportPdfOperation = exportPDF.Operation.createNew(exportPDF.SupportedTargetFormats.DOCX);
/* Commenting it to test s3 read//
// Set operation input from a source file
const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/exportPDFInput.pdf'); //about input
exportPdfOperation.setInput(input);
/ Commenting it to test s3 read*/
//Download from s3 //
const filePath = '/tmp/';
var s3 = new aws.S3();
const downloadFile = (filePath, bucket, key) => {
const params = {
Bucket: bucket,
Key: key
};
s3.getObject(params, (err, data) => {
if (err) console.error(err);
fs.writeFileSync(filePath, data.Body.toString());
console.log(`${filePath} has been created!`);
});
};
console.log('File downloaded')
//Changed till here//
// Execute the operation and Save the result to the specified location.
exportPdfOperation.execute(executionContext)
.then(result => result.saveAsFile(filePath+'exportPdfOutput.docx')) // about output
.catch(err => {
if(err instanceof PDFServicesSdk.Error.ServiceApiError
|| err instanceof PDFServicesSdk.Error.ServiceUsageError) {
console.log('Exception encountered while executing operation -1', err);
} else {
console.log('Exception encountered while executing operation-2', err);
}
});
console.log('File is in temp')
} catch (err) {
console.log('Exception at first try', err);
}
};
Пожалуйста, помогите и дайте мне знать, какая дополнительная информация вам нужна. Здесь выдается исключение «Исключение при выполнении операции-2»