Created
October 31, 2014 07:03
-
-
Save robksawyer/afd48842831edc599f58 to your computer and use it in GitHub Desktop.
Simple file processing function.
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
/** | |
* 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