diff --git a/lib/attachments.js b/lib/attachments.js index 7845355..403074e 100644 --- a/lib/attachments.js +++ b/lib/attachments.js @@ -139,6 +139,7 @@ var plugin = function(schema, options) { // path: String(required). Path to the file in the file system. // name: String(optional). Original Name of the file. // mime: String(optional). Mime type of the file. + // category: String(optional). A top-level grouping for the files. schema.methods.attach = function(propertyName, attachmentInfo, cb) { var selfModel = this; if(propertyNames.indexOf(propertyName) == -1) return cb(new Error('property "' + propertyName + '" was not registered as an attachment property')); @@ -168,7 +169,12 @@ var plugin = function(schema, options) { var finishConversion = function(styleFilePath, atts, cb) { var ext = path.extname(styleFilePath); var filenameId = options.filenameId ? selfModel[options.filenameId] : selfModel.id; - var storageStylePath = '/' + options.directory + '/' + filenameId + '-' + styleName + ext; + var storageStylePath; + if(attachmentInfo.category) { + storageStylePath = '/' + options.directory + '/' + attachmentInfo.category + '/' + filenameId + '-' + styleName + ext; + } else { + storageStylePath = '/' + options.directory + '/' + filenameId + '-' + styleName + ext; + } fs.stat(styleFilePath, function(err, stats) { if(err) return cb(err); cb(null, {