file upload issue...

file upload issue...

moonjikLeemoonjikLee Posts: 6Questions: 1Answers: 0
edited March 2020 in Free community support

I got the error message when file uploading with editor...
Error : "The "path" argument must be one of type string, Buffer, or URL. Received type undefined"

I spent a couple of days to solve this... but I don't know what's wrong..
Anyone help me??
Tnank you..

[ JavaScript ]

$(document).ready(function() {
    var editor = new $.fn.dataTable.Editor( {
        ajax:  '/admin/tables/upload/Patients',
        table: '#dataTable',
        fields: [
            { label: 'id', name: 'id', type:'readonly'},
            { label: 'Name', name: 'Name' },
            { label: 'RegDate', name: 'RegDate', type: 'datetime'},
            { label: 'Photo', 
                name: 'Photo',
                type: 'upload',
                display: function(file_id){
                return file_id;
                },
                noImageText: 'No Image'    
            },
            { label: 'Sex', name: 'Sex' },
            { label: 'Birth', name: 'Birth'},
            { label: 'ParmNumber', name: 'ParmNumber'},
            { label: 'ParmPatNum', name: 'ParmPatNum'},
            { label: 'QANumber', name: 'QANumber' },
            { label: 'TelNum', name: 'TelNum'},
            { label: 'Address', name: 'Address'},
            { label: 'Comment', name: 'Comment'},
            { label: 'ETC', name: 'ETC'},
            { label: 'LatestVisit', name: 'LatestVisit'}
        ]
    } );

    $('#dataTable').DataTable({
        language: {
            url: 'translation/korean'
        },
        bLengthChange: true,
        dom: 'Bfrtip',
        select: true,
        responsive: true,
        ajax: '/admin/tables/upload/Patients',
        columns: [
            {data: "id",},
            {data: "Name"},
            {data: "RegDate"},
            {data: "Photo",
                defaultContent: 'No Image'},
            {data: "Sex"},
            {data: "Birth"},
            {data: "ParmNumber"},
            {data: "ParmPatNum"},
            {data: "QANumber"},
            {data: "TelNum"},
            {data: "Address"},
            {data: "Comment"},
            {data: "ETC"},
            {data: "LatestVisit"}
        ],
        buttons: [
             {extend: 'create', editor:editor},
            {extend: 'edit', editor:editor},
            {extend: 'remove', editor:editor}
        ]
    });
  });

[ Node.js ]

module.exports.processUpload = function(req, res){
    var table = req.params.table;
    let editor = new Editor(knex, table)
               .fields(
                new Field('id'),
                new Field('Name'),
                new Field('RegDate'),
                new Field('Photo')
            // .upload(new Upload(__dirname + './../../../infoboxRes/{name}'))
                .upload(new Upload(function(fileInfo, id){
                    console.log(fileInfo);
                    rename(fileInfo.file, __dirname + './../../../infoboxRes/{name}')
                    .then(function(result){
                        console.log(result);
                    }).catch(function(err){
                        console.log(err);
                    });
                }))
                .setFormatter(Format.ifEmpty(null)),
                new Field('Sex'),
                new Field('Birth'),
                new Field('ParmNumber'),
                new Field('ParmPatNum'),
                new Field('QANumber'),
                new Field('TelNum'),
                new Field('Address'),
                new Field('Comment'),
                new Field('ETC'),
                new Field('LatestVisit')
            );


    // await editor.process(req.body)
    editor.process(req.body, req.files)
    .then(function(result){
        res.json(editor.data());
    }).catch(function(err){
        console.log(err);
        res.send(utils.makeResponse('500', err));
    })

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Can you show me the full backtrace your are getting on the Node console please?

    Thanks,
    Allan

  • moonjikLeemoonjikLee Posts: 6Questions: 1Answers: 0

    Thanks,
    The backtrace is

    "TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be one of type string, Buffer, or URL. Received type undefined\n
    at Function.stat (fs.js:887:10)\n
    at /Users/leemoonjik/devel/jbkLab/repository/server/node_modules/datatables.net-editor-server/dist/promisify.js:31:16\n
    at new Promise (<anonymous>)\n
    at /Users/leemoonjik/devel/jbkLab/repository/server/node_modules/datatables.net-editor-server/dist/promisify.js:20:16\n
    at Upload.<anonymous> (/Users/leemoonjik/devel/jbkLab/repository/server/node_modules/datatables.net-editor-server/dist/upload.js:273:50)\n
    at step (/Users/leemoonjik/devel/jbkLab/repository/server/node_modules/datatables.net-editor-server/dist/upload.js:32:23)\n
    at Object.next (/Users/leemoonjik/devel/jbkLab/repository/server/node_modules/datatables.net-editor-server/dist/upload.js:13:53)\n
    at /Users/leemoonjik/devel/jbkLab/repository/server/node_modules/datatables.net-editor-server/dist/upload.js:7:71\n
    at new Promise (<anonymous>)\n
    at __awaiter (/Users/leemoonjik/d...

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Perfect - thanks. That indicates that it is this line in the source that is failing.

    So upload.upload.file is undefined.

    If you do console.log( req.files ); in the controller, what does it show please? I'm not seeing anything particularly wrong with the code you are using, or the Editor code... Also what version of the NodejS library are you using? 1.9.2 is the latest release.

    Thanks,
    Allan

  • moonjikLeemoonjikLee Posts: 6Questions: 1Answers: 0

    the console.log(req.files) says "undefined". but "upload" Object has data about file to upload..

    console.log is

    Thanks,
    Moonjik

  • moonjikLeemoonjikLee Posts: 6Questions: 1Answers: 0
    edited March 2020

    Sorry, I looked into the sample code...
    I realize I missed 'express-busboy'
    after included the 'express-busboy', I got different message..

    message:"No upload data supplied"
    stack:"Error: No upload data supplied
    at Editor.<anonymous> (/Users/leemoonjik/devel/jbkLab/repository/server/node_modules/datatables.net-editor-server/dist/editor.js:1713:35)
    at step (/Users/leemoonjik/devel/jbkLab/repository/server/node_modules/datatables.net-editor-server/dist/editor.js:45:23)
    at Object.next (/Users/leemoonjik/devel/jbkLab/repository/server/node_modules/datatables.net-editor-server/dist/editor.js:26:53)
    at /Users/leemoonjik/devel/jbkLab/repository/server/node_modules/datatables.net-editor-server/dist/editor.js:20:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/leemoonjik/devel/jbkLab/repository/server/node_modules/datatables.net-editor-server/dist/editor.js:16:12)
    at Editor._upload (/Users/leemoonjik/devel/jbkLab/repository/server/node_modules/datatables.net-editor-server/dist/editor.js:1687:16)
    at Editor.<anonymous> (/Users/leemoonjik/devel/jbkLab/repository/server/node_modules/datatables.net-editor-server/dist/editor.js:1269:51)
    at step (/Users/leemoonj...

    I think it is about client side issue...
    Is there something to do with javascripts included?
    The javascript included in my html is

      <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
      <script src="../public/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
    
      <!-- Core plugin JavaScript-->
      <script src="../public/vendor/jquery-easing/jquery.easing.min.js"></script>
    
      <script src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"> </script>
      <script type="text/javascript" src="https://cdn.datatables.net/v/dt/jqc-1.12.4/dt-1.10.20/b-1.6.1/sl-1.3.1/datatables.min.js"></script>
      <script type="text/javascript" src="../public/vendor/Editor1.9.2/js/dataTables.editor.js"></script>
      <script src="https://cdn.datatables.net/buttons/1.6.1/js/dataTables.buttons.min.js"> </script> 
      <script src="https://cdn.datatables.net/select/1.3.1/js/dataTables.select.min.js"></script> 
      <script src="https://cdn.datatables.net/responsive/2.0.2/js/dataTables.responsive.min.js"></script> 
      <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.7/js/select2.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.full.js"></script>
    

    Do I need to include more script like shCore.js, demo.js, edittor-demo.js?
    Thanks,
    Moonjik

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    HI Moonjik,

    Do I need to include more script like shCore.js, demo.js, edittor-demo.js?

    No - those are demo files only.

    Are you able to give me a link to your page so I can debug it directly? I don't see anything wrong with the client-side code above. You could send me a PM (click my name above and then "Send message" if you don't want the link to be available publicly.

    Allan

  • moonjikLeemoonjikLee Posts: 6Questions: 1Answers: 0

    Hi allan,

    I found the reason. the reason is another upload library 'express-fileupload'.
    I use this library for upload file from mobile. when remove this library, it works..

    At this point, I have two question about file upload..
    1. Can I use Upload class instead of using upload library like 'multer' and 'express-fileupload' for file upload from Mobile(Android/iOS). or Do you have a tip for this?
    2. when file is uploaded and moved completely, I got no message from server. so I can't do any action. how can I return info that I want? my Node.js code is

               new Field('Photo')
                    .setFormatter(Format.ifEmpty(null))
                // .upload(new Upload(__dirname + './../../../infoboxRes/{name}'))
                    .upload(new Upload(function(fileInfo,id){
                        console.log(fileInfo);
                        let originalName = fileInfo.filename;
                        let splitName = originalName.split('.');
                        let tempName = + new Date();
                        let newName = splitName[0] + '_' + tempName + '.' + splitName[1];
                        fs.rename(fileInfo.file, __dirname + '/../../../infoboxRes/'+newName, function(err){
                            if(err){
                                console.log(err);
                            }else{
                                console.log('Completed');
                              // remove temp directory...
                                return newName;
                            }
    
                        });
                    })),
    

    From above code, I want to return newName.

    Thanks for your help,
    Moonjik

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Hi Moonjik,

    1. Can I use Upload class instead of using upload library like 'multer' and 'express-fileupload' for file upload from Mobile(Android/iOS).

    The Upload class is server-side, so the fact that you are using mobile on the client-side shouldn't make any difference.

    1. when file is uploaded and moved completely, I got no message from server. so I can't do any action. how can I return info that I want?

    I'm afraid I'll need more information on this. What do you mean you get no information from the server? The upload function should return that identifier for the file - see https://editor.datatables.net/manual/server#Upload

    Allan

  • novaznovaz Posts: 1Questions: 0Answers: 0
    edited August 2021

    f

Sign In or Register to comment.