File Upload with Editor / Node.js

File Upload with Editor / Node.js

tnaeschertnaescher Posts: 22Questions: 6Answers: 0

Hi everyone,

I tried adding a File upload field but got this error:

Unhandled promise error: [object Promise]Error: No upload data supplied

console.log(req.body) gives this:
{ action: 'upload', uploadField: 'image' }

I used the code identically to the example in https://editor.datatables.net/examples/advanced/upload.html
Field Definition Editor:

            {
                label: "Image:",
                name: "image",
                type: "upload",
                display: function ( file_id ) {
                    return '<img src="'+editor.file( 'files', file_id ).web_path+'"/>';
                },
                clearText: "Clear",
                noImageText: 'No image'
            }

Backend Node.js:

new Field("image").setFormatter(Format.ifEmpty(null)).upload(
      new Upload(__dirname + "/../public/uploads/kaufbelege/{id}.{extn}").db(
        "images",
        "id",
        {
          fileName: Upload.Db.FileName,
          fileSize: Upload.Db.FileSize,
        }
      )
    ),

Any ideas?

Best Regards
Timothy

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin
    Answer ✓

    Hi Timothy,

    Are you calling the Editor.process() method with the second parameter (req.files)?

    It should look like this:

    await editor.process(req.body, req.files);
    

    Regards,
    Allan

  • tnaeschertnaescher Posts: 22Questions: 6Answers: 0

    Hi Allan,

    oh my, that was an easy fix. Thanks :)
    It's the first time I have to use Node.js, still a lot to get used to...

    Best,
    Timothy

  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin

    No worries! A new API always takes time to learn, even if you've been working with Node for years a new library might take a little while. Great to hear that did the job!

    Allan

Sign In or Register to comment.