I was using cloudconvert api from node JS, which was working fine when I hosted in heroku. But when I made netlify serverless function it is returning error. Is it because serverless function exits before completing the task?
try {
let job = await cloudConvert.jobs.create({
tasks: {
'const-1': {
operation: 'const/raw',
// file: file_string_output,
file: '<div>Welcome ... testing...</div>',
filename: `${fileName}.html`,
},
'task-1': {
operation: 'convert',
input_format: 'html',
output_format: 'pdf',
engine: 'chrome',
input: ['const-1'],
zoom: 1,
print_background: true,
display_header_footer: false,
wait_until: 'load',
wait_time: 0,
},
'export-1': {
operation: 'export/s3',
input: ['task-1'],
bucket: process.env.S3_BUCKET_NAME,
region: process.env.S3_BUCKET_REGION,
access_key_id: process.env.S3_ACCESS_KEY,
secret_access_key: process.env.S3_ACCESS_SECRETE,
key: `${process.env.S3_BUCKET_FOLDER}/${fileName}.pdf`,
},
},
})
cloudConvert.jobs.subscribeEvent(job.id, 'finished', (event) => {
console.log('cloud convert stages finished', event.job)
})
cloudConvert.jobs.subscribeEvent(job.id, 'error', (event) => {
console.log('error', event.job)
})
cloudConvert.jobs.subscribeTaskEvent(job.id, 'finished', async (event) => {
console.log('cloud convert Task stages finished', event.job)
})
cloudConvert.jobs.subscribeTaskEvent(job.id, 'error', (event) => {
console.log('Task on error', event.task)
})
} catch (error) {
console.log(' Cloud convert key is invalid??:', error)
}
I have figured out the problem. In below code, there was a typo. operation: 'const/raw', ==>>>> operation: 'import/raw'
It was my bad. Since the netlify serverless did not support Es6, I have to change all import syntax to require() syntax and I had a global search and replace import==> const which effected here as well. So silly me...