Just like as the title says, I am trying to upload a file to a remote server using Angular's ngFileUpload and as middleware, I use express' connect-multiparty.
The Angular part looks like this:
var upload = Upload.upload({
url: 'api/uploadAttachments',
method: 'POST',
data: {
file: file
},
params: {
id: $scope.project.id
}
});
upload.then(function (res) {
console.log(res);
});
and then on node:
api.post('/uploadAttachments', multipartyMiddleware, UserController.uploadFile);
then on UserController.js
var requestLib = require("request");
UserController = function() {};
UserController.prototype.uploadFile = function(req, res) {
requestLib({
url: 'https://www.myserverexample.com/api/uploads',
method: "POST",
headers: {
'Accept' : 'application/json, text/plain, */*',
'Content-Type': 'multipart/form-data'
},
qs: {
pid: req.query.id
},
data: {
deliveryAttachment: req.files.file
}
}, function (error, response, body) {
res.send(body);
});
}
module.exports = new UserController();
After I upload, I get this object in return on the frontend:
{data: "", status: 200, config: Object, statusText: "OK", headers: function}
Am I missing something here? Any help is definitely appreciated! :)
via Growlithe
No comments:
Post a Comment