Created
August 7, 2017 07:36
-
-
Save sachinsmc/7d8e56c466e3e79495039f71af0629f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Files.upload = function (ctx,options,cb) { | |
if(!options) options = {}; | |
console.log('File Uploading.....'); | |
//console.log(ctx.req.headers['mobile']); | |
//console.log(ctx.mobile); | |
ctx.req.params.container = 'common'; | |
Files.app.models.container.upload(ctx.req,ctx.result,options,function (err,fileObj) { | |
if(err) { | |
cb(err); | |
} else { | |
var fileInfo = fileObj.files.file[0]; | |
// console.log(ctx.mobile); | |
Files.create({ | |
name: fileInfo.name, | |
type: fileInfo.type, | |
url: CONTAINERS_URL+fileInfo.container+'/'+fileInfo.name | |
},function (err,obj) { | |
if (err !== null) { | |
cb(err); | |
} else { | |
var mobile=ctx.req.mobile; | |
//console.log('mobile : '+mobile); | |
Files.app.models.namaste_user.updateAll({ | |
mobile: mobile | |
}, { | |
pic:fileInfo.name | |
}, function(err, updateresult) { | |
if(err){ | |
console.log(err); | |
} | |
console.log('fileinfo: '+fileInfo.name); | |
}); | |
var objs={ | |
"message":"user profile pic uploaded.", | |
"response_code":"200", | |
"status":true, | |
"type":obj.type, | |
"url":obj.url | |
} | |
cb(null, objs); | |
} | |
}); | |
} | |
}); | |
}; | |
Files.remoteMethod( | |
'upload',{ | |
description: 'Uploads a file', | |
accepts: [ | |
{ arg: 'ctx', type: 'object', http: { source:'context' } }, | |
{ arg: 'options', type: 'object', http:{ source: 'query'} } | |
], | |
returns: { | |
arg: 'fileObject', type: 'object', root: true | |
}, | |
http: {verb: 'post'} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment