Skip to content

Instantly share code, notes, and snippets.

@robksawyer
Created October 31, 2014 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robksawyer/afd48842831edc599f58 to your computer and use it in GitHub Desktop.
Save robksawyer/afd48842831edc599f58 to your computer and use it in GitHub Desktop.
Simple file processing function.
/**
* CampaignController
*
* @description :: Server-side logic for managing campaigns
* @help :: See http://links.sailsjs.org/docs/controllers
*/
module.exports = {
fileExtension: function(fileName) {
return fileName.split('.').slice(-1);
},
process: function(req, res){
// e.g.
// 0 => infinite
// 240000 => 4 minutes (240,000 miliseconds)
// etc.
//
// Node defaults to 2 minutes.
res.setTimeout(0);
sails.log(req.file('xFile'));
req.file('xFile').upload({
// You can apply a file upload limit (in bytes)
maxBytes: 1000000
}, function whenDone(err, uploadedFiles, $scope){
if(err) {
return res.serverError(err);
} else {
if(typeof require !== 'undefined') {
XLSX = require('xlsx');
}
sails.log(fileExtension(uploadedFiles[0].filename));
/*var workbook = XLSX.readFile(req.xfile);
sails.log(workbook);*/
return res.json({
files: uploadedFiles,
textParams: req.params.all()
});
}
});
},
upload: function(req, res){
return res.view();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment