Editor node.js file upload example error - A server error occurred while uploading the file
I'm not getting the basic file upload example to run:
https://editor.datatables.net/manual/nodejs/upload
In the frontend I'm getting:
A server error occurred while uploading the file
... when trying to upload a file.
let {
Editor,
Field,
Validate,
Format,
Options,
Upload,
promisify
} = require('datatables.net-editor-server');
let unlink = promisify(fs.unlink); // await version of unlink
var getBody = JSON.parse(req.body.json);
let editor = new Editor( db, 'news', 'id' )
.fields(
new Field( 'news.id', 'id' ),
new Field( 'news.cruser_id', 'cruser_id' ),
new Field( 'news.image', 'image' ).setFormatter( Format.ifEmpty(null) ).upload(
new Upload( __dirname + '/../public/uploads/{id}.{extn}' )
.db('image', 'id', {
fileName: Upload.Db.FileName,
fileSize: Upload.Db.FileSize,
web_path: '/uploads/{id}.{extn}',
system_path: Upload.Db.SystemPath
})
.validator( Validate.fileSize(500000, 'Files must be smaller than 500K') )
.validator(
Validate.fileExtensions(
['png', 'jpg', 'gif'],
'Only image files can be uploaded (png, jpg and gif)'
)
)
.dbClean(async function(data) {
for (let i = 0, ien = data.length; i < ien; i++) {
await unlink(data[i].system_path);
}
return true;
})
)
)
await editor.process(getBody, req.files);
res.json(editor.data());
What am I missing and How can I solve this?