I have to create a preview image for each file which is uploaded into my Google Cloud Storage bucket. For this I am using the filepreview
npm package.
After I upload the file, I should see new image with the file preview, but this is missing and the error log says:
Error: spawnSync file ENOENT
at exports._errnoException (util.js:1020:11)
at spawnSync (child_process.js:451:20)
at Object.execFileSync (child_process.js:488:13)
at Object.generate (/user_code/node_modules/filepreview/filepreview.js:41:40)
at exports.generatePreviewImage.event (/user_code/index.js:27:22)
at /var/tmp/worker/worker.js:770:24
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
I suppose the path to the file is not correct. Could this be the problem? The name of the file uploaded is kitten.png
. Here is my function:
exports.generatePreviewImage = event => {
const object = event.data || event; // Node 6: event.data === Node 8+: event
const file = storage.bucket(object.bucket).file(object.name);
const filePath = `gs://${object.bucket}/${object.name}`;
const newFilePath = `gs://${object.bucket}/${object.name}-thumb.png`;
console.log(`filePath: ${filePath}`); // This logs 'file: gs://my-bucket/kitten.png'
console.log(`newFilePath: ${newFilePath}`); // This logs 'gs://my-bucket/kitten.png-thumb.png'
return filepreview.generate(filePath, newFilePath, function(error) {
if (error) {
return console.log('Error is now: ', error);
}
console.log(`File preview is: ${newFilePath}`);
});
}