I created a Simple file uploading Application with loopback. Application client side i used simple html and Java Script code .
i calling a loopback api with ajax call , this is Java Script code -
$('#upload-input').on('change', function () {
var files = $(this).get(0).files;
if (files.length > 0) {
// One or more files selected, process the file upload
var form = new FormData();
for (var index = 0; index < files.length; index++) {
var file = files[index];
form.append('Uploded Files', file, file.name);
}
$.ajax({
url: 'api/fileupload/upload',
type: 'POST',
data: form,
processData: false,
contentType: false,
success: function (data) {
console.log('upload successful!');
}
});
}
});
But we are not getting files on server side . On Server side we Created a Loopback api .
can any help us , how to upload files with loopback api .
This is my loopback api code -
FileUpload.remoteMethod
( 'upload', { http: { verb: 'post', }, accepts: [ { arg: 'ctx', type: 'object', http: { source: 'context' } }, { arg: 'options', type: 'object', http: { source: 'query' } }
],
returns: {
arg: 'data',
type: 'string',
root: true
}
}
);
FileUpload.upload = function (context, options, callback) {
//context.req.params = 'common';
};
via Rakesh
No comments:
Post a Comment