Skip to content

Commit

Permalink
allow uploading of local files
Browse files Browse the repository at this point in the history
  • Loading branch information
madhums committed Aug 24, 2012
1 parent 34e49a6 commit 33311b0
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions lib/imager.js
Expand Up @@ -29,9 +29,29 @@ var Imager = exports = module.exports = function Imager(config, storage) {


Imager.prototype.upload = function (files, callback, variant) { Imager.prototype.upload = function (files, callback, variant) {
var self = this 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') // to check if the files are local
throw new Error('Please provide a valid file') 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') if (typeof callback !== 'function')
throw new Error('Please provide a callback') throw new Error('Please provide a callback')
Expand Down Expand Up @@ -85,9 +105,9 @@ Imager.prototype.startUpload = function (file, filename, variant, iteratorCallba
async.parallel(asyncArr, function (err, results) { async.parallel(asyncArr, function (err, results) {
if (err) console.log(err) if (err) console.log(err)
var f = _.uniq(results).toString() var f = _.uniq(results).toString()

f = f.indexOf(',') === -1 ? f : f.slice(0, f.length - 1) f = f.indexOf(',') === -1 ? f : f.slice(0, f.length - 1)

self.uploadedFiles.push(f) self.uploadedFiles.push(f)
console.log(self.uploadedFiles) console.log(self.uploadedFiles)
iteratorCallback(err) iteratorCallback(err)
Expand Down

0 comments on commit 33311b0

Please sign in to comment.