I want to dynamically change the upload image path based on parameter of the form post. I'm not using formidable which would be easy but instead using express with bodyParser enabled and by setting the default upload path as configuration on main app. How do I access this in the future? I want to change this path dynamically based on the users input so it could lets say be public/img/2009/someProject. The last 2 path selectors are dynamic. The public/img is set as default config in express bodyParser.
Here is a similiar question below but i could'nt find a good answer. how can I access the uploadDir attribute of express?
// set in the main app.js
app.configure(function() {
app.use(express.bodyParser({
uploadDir: __dirname + '\\public\\img',
keepExtensions: true
}));
});
// need to set the upload path here
exports.addPortfolio = function(req, res) {
var portfolio = req.body,
parseName = req.body.name,
pathName = parseName.replace(/\s+/g, '-').toLowerCase();
console.log('Adding portfolio: ' + JSON.stringify(portfolio));
console.log(req.body.year);
console.log('parseName'+parseName);
// attempt to overwrite here
app.use(express.bodyParser({
uploadDir: __dirname + '\\public\\img\\'+req.body.year+'\\'+pathName
}));
db.collection('portfolios', function(err, collection) {
collection.insert(portfolio, {safe:true}, function(err, result) {
if (err) {
res.send({'error':'An error has occurred'});
} else {
console.log('Success: ' + JSON.stringify(result[0]));
res.send(result[0]);
}
});
});
};