I have a MEAN.js application in which I use https://github.com/nervgh/angular-file-upload to handle angular file uploads to server. What I want to do is receive the files on the server, and then pipe them to another server where I would like to use a writeStream to write them.
Is there a way I can do this?
ar data = {
file : {
buffer:req.files.file.buffer,
filename : req.files.file.name,
content_type : 'application/octet-stream'
},
options : {
operation : 'Content',
source : req.body.source
}
};
needle.post(config.vdnURL,data,{ multipart:true},function(error, response) {
on the other server which is supposed to receive the file and write it to disk, I do the following
mkdirp(config.winUploadPath+ req.body.options.source + '/'+ req.body.options.operation +'/', function(err) {
if (err) {
console.log(err);
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
fs.writeFile(config.winUploadPath + req.body.options.source + '/'+ req.body.options.operation +'/' + req.files.file.name, req.files.file.buffer, function (uploadError) {
if (uploadError) {
console.log('Got upload error ', uploadError);
return res.status(400).send({
message: 'Error occurred while uploading profile picture'
});
} else {
res.status(200).send({
message: 'Upload successful',
url: req.body.options.source + '/'+ req.body.options.operation +'/' + req.files.file.name
});
}
});
}
});
The problem arises when the file size exceeds a couple of MB's (>3-4MB). Files don't get written at all and the second server shows
POST / -- ms -- with no file written.
Hence I thought its a streaming problem. Any help on how maybe I can solve it will be greatly appreciated.