I am using the following sample client code to send the multipart/form-data from client:
let formData = new FormData();
var task ={"description":"this is first test task","sequenceNumber":1,"companyId":"1"};
formData.append('task', task);
formData.append('attachments', data.profile_pic[0]);
const config = {
headers: { 'content-type': 'multipart/form-data' }
}
post('http://localhost:3000/api/tasks/saveAll', formData, config);
Server side is a loopback application and i have defined the following remote method to handle the above request: (I have also followed SO and did the required changes)
Tasks.remoteMethod('saveAll', {
accepts: [{arg: 'task', type: 'object', http: { source: 'body' }},
{arg: 'req', type: 'object', 'http': {source: 'req'}},
{arg: 'res', type: 'object', 'http': {source: 'res'}}],
http: {verb: 'post'},
returns: {arg: 'task', type: 'object'}
});
Tasks.saveAll = function(task, req, res, cb) {
console.log('save all remote methid called' + JSON.stringify(task));
});
it always returns empty object{}. How do i get the task json which i sent from client in the remote method? I need to post attachment to a different server than JSON, so need to segregate data in remote method, but unable to read the task json set by client. Please suggest whats missing.
Any example similar to this requirement would help as well.
I am using the following sample client code to send the multipart/form-data from client:
Server side is a loopback application and i have defined the following remote method to handle the above request: (I have also followed SO and did the required changes)
it always returns empty object{}. How do i get the task json which i sent from client in the remote method? I need to post attachment to a different server than JSON, so need to segregate data in remote method, but unable to read the task json set by client. Please suggest whats missing.
Any example similar to this requirement would help as well.