Permalink
Browse files

allow uploading of local files

  • Loading branch information...
1 parent 34e49a6 commit 33311b05f81283b3bc5c58a46b4f9e4d3480465f @madhums committed Aug 24, 2012
Showing with 24 additions and 4 deletions.
  1. +24 −4 lib/imager.js
View
@@ -29,9 +29,29 @@ var Imager = exports = module.exports = function Imager(config, storage) {
Imager.prototype.upload = function (files, callback, variant) {
var self = this
+ , getFileInfo = function (file, cb) {
+ var f = {
+ size: fs.statSync(file).size
+ , type: mime.lookup(file)
+ , name: file.split('/')[file.split('/').length - 1]
+ , path: file
+ }
+ file = f
+ cb(null, file)
+ }
- if (typeof files !== 'string' && typeof files !== 'object')
- throw new Error('Please provide a valid file')
+ // to check if the files are local
+ if (Array.isArray(files) && typeof files[0] === 'string') {
+ async.map(files, getFileInfo, function (err, result) {
+ files = result
+ })
+ }
+ else if (!Array.isArray(files) && typeof files === 'string') {
+ files = files.split()
+ async.map(files, getFileInfo, function (err, result) {
+ files = result
+ })
+ }
if (typeof callback !== 'function')
throw new Error('Please provide a callback')
@@ -85,9 +105,9 @@ Imager.prototype.startUpload = function (file, filename, variant, iteratorCallba
async.parallel(asyncArr, function (err, results) {
if (err) console.log(err)
var f = _.uniq(results).toString()
-
+
f = f.indexOf(',') === -1 ? f : f.slice(0, f.length - 1)
-
+
self.uploadedFiles.push(f)
console.log(self.uploadedFiles)
iteratorCallback(err)

0 comments on commit 33311b0

Please sign in to comment.