I have a schema for attachments:
var mongoose = require('mongoose');
var s3 = require('./config/secrets').s3;
var provider = require('mongoose-attachments-aws2js');
var attachments = require('mongoose-attachments');
attachments.registerStorageProvider('aws2js', provider);
var attachmentSchema = new mongoose.Schema({
name: String,
date_created: {type: Date, default: new Date()},
is_active: {type: Boolean, default: true}
});
attachmentSchema.plugin(attachments, {
directory: 'HowToChangeThis',
storage : {
providerName: 'aws2js',
options: {
key: s3.key,
secret: s3.secret,
bucket: s3.bucket,
acl: 'public-read'
}
},
properties: {
file: {
styles: {
original: {
// keep the original file
}
}
}
}
});
module.exports = mongoose.model('Attachment', attachmentSchema);
This schema is used within different docs: events (attachment is an event image), users (attachments is an avatar), location (attachment is a location photo), etc. But I don't want to upload all attachments to 1 remote directory. Is there any way to change mongoose-attachments-aws2js directory dynamically and keep only 1 schema for all attachments?