Trouble debugging "A server error occurred while uploading the file" [nodejs/editor v1.9.4]

Trouble debugging "A server error occurred while uploading the file" [nodejs/editor v1.9.4]

makeitaboldmovemakeitaboldmove Posts: 3Questions: 0Answers: 0

Hey all,

I'm receiving the "A server error occurred while uploading the file" error on the front-end and the server-side is returning no errors.

The response I receive in Chrome returns nothing of note:

cancelled: []
data: []
debug: []
fieldErrors: []
files: {}
options: {}
searchPanes: {options: {}}

Here is a block of our server-side code:

app.post('/api/admin/product-material', async(req, res) => {

    let user = req.body.user;
    let editor = new Editor(db, 'product_material').fields(

        new Field('user.id'),
        new Field('user.first_name'),
        new Field('user.last_name'),
        new Field('user.code'),

        new Field('product_material.filename')
            .upload(new Upload(__dirname + "/uploads/{id}.{extn}")
                .db('product_material', 'product_material.id', {
                    filename : Upload.Db.FileName,
                    original_filename : Upload.Db.FileName,
                    ext : Upload.Db.Extn,
                    mime_type : Upload.Db.MimeType,
                    filesize : Upload.Db.FileSize
                })
            )
            .setFormatter(Format.ifEmpty(null)),

        new Field('product_material.category_id'),
        new Field('product_material.ext'),
        new Field('product_material.mime_type'),
        new Field('product_material.filesize'),
        new Field('product_material.created_at'),
        new Field('product_material.deleted_at')
            .setFormatter(Format.ifEmpty(null)),

    )
    .leftJoin('user', 'product_material.user_id', '=', 'user.id')
    .on('preRemove', (editor, id, values) => {
        return false;
    });
    editor.where(function(){
        this.where('product_material.deleted_at', null);
    });
    await editor.process(req.body);
    res.json(editor.data());
});

And the front-end editor fields code block:

editor = new $.fn.dataTable.Editor({
    ajax: {
        "url": "https://safeharborfinance.com/api/admin/product-material",
        "data": (data) => {
            data.user = <?= json_encode($user); ?>;
        },
        "type": "post"
    },
    table: "#product-materials",
    fields: [
        {
            label: "File",
            name: "product_material.filename",
            type: "upload",
            defaultContent: "No file",
            title: "File"
        }, {
            label: "Categories",
            name: "product_material.category_id"
        },
    ],
    formOptions: {
        inline: {
            onBlur: 'submit'
        }
    }
});

I do not want to store the files into a separate table as shown in the documentation, so I'm thinking that maybe the issue I'm experiencing. I set the permissions to 777 temporarily to see if that was the issue, and it was not.

Replies

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,947

    Someone more familiar with the server side code you are using may be able to help. The problem is likely due to the response is not the expected Upload response. The Editor Client Server Exchange docs show what is expected.

    Kevin

  • makeitaboldmovemakeitaboldmove Posts: 3Questions: 0Answers: 0

    I think this is a start...

    For some reason console.log(req.body); returns {} when attempting to upload a file.

    However, console.log(req.body); returns {user : { id: 1, name: 'Me', etc: 'etc' } } on initial page/table loads.

    Any idea why this is happening if I'm using similar code as presented in the documentation? Who can I/you ping to get more help on this?

    Thanks, Kevin!

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin

    If you have a look at the console in which you are running your node server, does that show anything?

    Also are you using a module such as busboy to parse multi-part forms? Our demo package uses express-busboy for example:

    bb.extend( app, {
        upload: true
    } );
    

    Allan

  • makeitaboldmovemakeitaboldmove Posts: 3Questions: 0Answers: 0
    edited August 2020

    Allan,

    Implementing busboy has gotten me a bit closer, but now I'm getting this error.

    (node:771925) UnhandledPromiseRejectionWarning: Error: No upload data supplied
    

    And console.log(req.body); now shows this.

    {
      action: 'upload',
      uploadField: 'product_material.filename',
      user: '[object Object]'
    }
    

    Thank you for your help!

This discussion has been closed.