Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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, {
Expand Down