Ejemplo n.º 1
0
container.register('mongooseAttachments', function () {
    var attachments = require('mongoose-attachments'),
        LocalfsStorage = require('mongoose-attachments-localfs');

    attachments.registerStorageProvider('localfs', LocalfsStorage);

    return attachments;
});
      }
      cb(null, oldKeys);
    });
  };

  var deleteOldKeys = function(oldKeys, cb) {
    if(self.options.keepOldFiles && self.options.uniqueStoragePath) return cb(null);
    if(oldKeys.length === 0) return cb(null);
    self.client.delMultiObjects(oldKeys, cb);
  };

  getOldKeys(function(err, oldKeys) {
    self.client.putFile(attachment.path,attachment.filename, self.acl, {}, function(err, uploadRes) {
      if(err) return cb(err);
      attachment.defaultUrl = self.getUrl( attachment.path );
      deleteOldKeys(oldKeys, function(err) {
        if(err) return cb(err);
        cb(null, attachment);
      });
    });

  });

};

// register the S3 Storage Provider into the registry
attachments.registerStorageProvider('aws2js', S3Storage);

// export it just in case the user needs it
module.exports = S3Storage;