Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add S3 upload and remove functionality

  • Loading branch information...
commit bd3f4fc054dfb51481fcd3a098faa58ef913ff29 1 parent 19df790
@madhums madhums authored
Showing with 27 additions and 2 deletions.
  1. +27 −2 lib/imager.js
View
29 lib/imager.js
@@ -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')
@@ -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')
@@ -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)
+ })
+}
Please sign in to comment.
Something went wrong with that request. Please try again.