file upload issue...
file upload issue...
moonjikLee
Posts: 6Questions: 1Answers: 0
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
Can you show me the full backtrace your are getting on the Node console please?
Thanks,
Allan
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...
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
the console.log(req.files) says "undefined". but "upload" Object has data about file to upload..
console.log is
Thanks,
Moonjik
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
Do I need to include more script like shCore.js, demo.js, edittor-demo.js?
Thanks,
Moonjik
HI Moonjik,
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
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
From above code, I want to return newName.
Thanks for your help,
Moonjik
Hi Moonjik,
The
Upload
class is server-side, so the fact that you are using mobile on the client-side shouldn't make any difference.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
f