I'm sorry about my English. I am use MEAN stack for writting my app. I find out some modules for uploading image and angular-file-upload is my choice. But when I upload the image the percent show on console completed. I'm check upload directory. The file is uploaded but can not read in Image Viever.
Here my code on angular :
$scope.onFileSelect = function($files) {
for (var i = 0; i < $files.length; i++) {
var file = $files[i];
$scope.upload = $upload.upload({
url: '/posts/upload/',
method: 'POST',
file: file,
}).progress(function(evt) {
console.log('percent: ' + parseInt(100.0 * evt.loaded / evt.total));
}).success(function(data, status, headers, config) {
// file is uploaded successfully
console.log(data);
});
}
};
Here my code on Node JS :
exports.upload = function(req, res) {
var data = new Buffer('');
req.on('data', function(chunk) {
data = Buffer.concat([data, chunk]);
});
req.on('end', function() {
req.rawBody = data;
fs.writeFile(config.root + path.sep + 'public/upload' + path.sep + uuid.v1(), data ,function(err){
if(err) throw err;
console.log('ok saved')
});
res.send('ok');
});
}
I guess I do something wrong with Node but I can't find out it. Please tell me what my mistake.