I'm working on handling file uploads using express.js ,node, and angular. The basic functionality working for small size images. While i try to upload larger images, i got 404 error . I use angular-file-upload. This is my file upload codings
$upload.upload({
url: '/products/image/upload',
data: {
PRODUCT_ID : productId,
},
file: file
}).progress(function(evt){
console.log('percent: ' + parseInt(100.0 * evt.loaded / evt.total, 10));
}).success(function(data){
console.log(data);
});
This is my express js code
app.post('/products/image/upload', controller.uploadProductImage);
exports.uploadProductImage = function(req, res){
var fileObject = req.files.file;
var newPath = '';
var newFilename = 'sample.png';
newPath = './uploads/products/' + newFilename;
fs.rename(fileObject.path, newPath, function(err) {
if (err) throw err;
fs.unlink(fileObject.path , function() {
if (err) throw err;
});
});
res.json({success:true});
};
I have posted here only the sample code. It works good for smaller size image. But if i upload a large size images, the route is shown as 404 error message. I hope it would be some config issue, like memory, process limit. I am not sure what is the exact problem .
I have tried to set the limit in express script like
app.use(express.limit('2mb'));
It is not worked for me. And i tried
node --max-old-space-size=2000 app.js
Bad luck. Please help me to resolve this problem
Thanks in advance