I'm using nodejs + multer + express the file is uploading but no response correct in the server side.
curl -F 'file=@logo.png' http://mysite.de:8080/upload/image
app.use(multer({ dest: '/var/www/likeyou-new/upload/image',
limits: {
fieldNameSize: 999999999,
fieldSize: 999999999
},
includeEmptyFields: true,
inMemory: true,
onFileUploadStart: function(file) {
console.log('Starting ' + file.fieldname);
},
// onFileUploadData: function(file, data) {
// console.log('Got a chunk of data!');
// },
onFileUploadComplete: function(file) {
console.log('Completed file!');
},
onParseStart: function() {
console.log('Starting to parse request!');
},
onParseEnd: function(req, next) {
console.log('Done parsing!');
next();
},
onError: function(e, next) {
if (e) {
console.log(e.stack);
}
next();
}}));
app.post('/upload/image', function(req, res,body){
console.log(req.body) // form fields
console.log(req.files) // form files
res.status(204).end()
var locate = '/var/www/likeyou-new/upload/image/'+"xx.png";
fs.writeFile(locate, req.files, function (err,data) {
if (err) {
return console.log(err);
}
console.log(data);
});
});
I receive in the server side:
{ file:
{ fieldname: 'file',
originalname: 'logo.png',
name: '1042553d1dfb648ba305b39f184d28dc.png',
encoding: '7bit',
mimetype: 'application/octet-stream',
path: '/var/www/new/upload/image/1042553d1dfb648ba305b39f184d28dc.png',
extension: 'png',
size: 820681,
truncated: false,
buffer: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 01 2c 01 2c 00 00 ff ee 00 0e 41 64 6f 62 65 00 64 00 00 00 00 00 ff e1 10 b8 45 78 69 66 00 00 4d 4d 00 2a 00 ...> } }
when i checked the destiny /var/www/new/upload/image nothing ther... what I'm doing wrong... i think the file upload ... but not storage the file...