-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
When i upload files with meta function as seen in http://stackoverflow.com/questions/28885282/how-to-store-files-with-meta-data-in-loopback
Everything worked BUT the formData sent along with the upload.
Kindly help, How i get the data i sent along with file upload,
My Code is Given Below
``'use strict';
module.exports = function(Upload) {
Upload.upload = function(ctx,options,cb){
if(!options) options = {};
console.log(ctx);cb();
Upload.app.models.auth.findById(ctx.req.accessToken.userId,{},function(err,data){
if(err) {
return cb(err);
}
ctx.req.params.container = 'institution_'+data.institutionId;
Upload.app.models.storage.upload(ctx.req,ctx.result,options,function(err,fileObj){
if(err) {
return cb(err);
} else {
var fileInfo = fileObj.files.file[0];
Upload.app.models.upload.create({
filename: fileInfo.name,
authId: ctx.req.accessToken.userId,
institutionId: data.institutionId,
type: fileInfo.type,
size: fileInfo.size,
container: fileInfo.container,
url: '/api/storages/'+ fileInfo.container +'/download/'+fileInfo.name,
lastModified: fileInfo.lastModified
},function(err,obj){
if (err) {
return cb(err);
} else {
return cb(null, obj);
}
});
}
});
});
}
Upload.remoteMethod('upload',{
description: 'Uploads a file and Record in Database',
accepts: [
{ arg: 'ctx', type: 'object', http: {source:'context'}},
{ arg: 'options', type: 'object', http:{source:'body'}}
],
returns: {arg: 'fileObject', type: 'object', root: true},
http: {verb: 'post',path: '/upload'}
});
};
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels