Skip to content

Commit

Permalink
add S3 upload and remove functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
madhums committed Sep 25, 2012
1 parent 19df790 commit bd3f4fc
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions lib/imager.js
Expand Up @@ -3,8 +3,7 @@ var gm = require('gm').subClass({ imageMagick: true })
, path = require('path')
, mime = require('mime')
, cloudfiles = require('cloudfiles')
, http = require('http')
, url = require('url')
, knox = require('knox')
, async = require('async')
, _ = require('underscore')

Expand Down Expand Up @@ -218,6 +217,19 @@ Imager.prototype.pushToRackspace = function (file, remoteFile, filename, type, c
}


Imager.prototype.pushToS3 = function (file, remoteFile, filename, type, cb) {
var self = this
, client = knox.createClient(this.config['storage'][this.storage])

client.putFile(file, remoteFile, function (err, res) {
if (err) return cb(err)
if (self.config.debug) console.log(remoteFile + ' uploaded')
self.cdnUri = 'http://' + client.endpoint
cb(err, filename)
})
}


Imager.prototype.remove = function (files, callback, variant) {
if (!variant && !this.config.variants.default)
throw new Error('Please specify a proper variant to remove the files')
Expand Down Expand Up @@ -300,3 +312,16 @@ Imager.prototype.removeFromRackspace = function (file, preset, cb) {
})
})
}


Imager.prototype.removeFromS3 = function (file, preset, cb) {
var self = this
, client = knox.createClient(this.config['storage'][this.storage])
, remoteFile = preset + '_' + file

client.deleteFile(remoteFile, function(err, res){
if (self.config.debug) console.log(remoteFile + ' removed')
if (err) console.log(err)
cb(err)
})
}

0 comments on commit bd3f4fc

Please sign in to comment.