Commit 5c517cb4 authored by Rosanny Sihombing's avatar Rosanny Sihombing
Browse files

fixing upload pictures

parent 3a4f8cad
This commit is part of merge request !31. Comments created here will be created in the context of that merge request.
Showing with 48 additions and 31 deletions
+48 -31
...@@ -164,12 +164,35 @@ module.exports = function (app) { ...@@ -164,12 +164,35 @@ module.exports = function (app) {
var projectLogo = req.files.logo var projectLogo = req.files.logo
var projectPicture = req.files.src var projectPicture = req.files.src
var projectLogoPath, projectPicturePath
if (projectLogo) {
// raise error if size limit is exceeded
if (projectLogo.size === pictSizeLimit) {
req.flash('error', 'Projektlogo exceeds 1 MB');
res.redirect('/addprojectoverview');
}
else {
// TEST PATH FOR DEVELOPMENT (LOCALHOST) // TEST PATH FOR DEVELOPMENT (LOCALHOST)
var projectLogoPath = './folder-in-server-to-save-projektlogo/'+req.body.pname+'/'+projectLogo.name projectLogoPath = './folder-in-server-to-save-projektlogo/'+req.body.pname+'/'+projectLogo.name
var projectPicturePath = './folder-in-server-to-save-projektbild/'+req.body.pname+'/'+projectPicture.name
// PATH FOR TEST/LIVE SERVER // PATH FOR TEST/LIVE SERVER
// var projectLogoPath = to-be-defined // var projectLogoPath = to-be-defined
}
}
if (projectPicture) {
// raise error if size limit is exceeded
if (projectPicture.size === pictSizeLimit) {
req.flash('error', 'Projektbild exceeds 1 MB');
res.redirect('/addprojectoverview');
}
else {
// TEST PATH FOR DEVELOPMENT (LOCALHOST)
projectPicturePath = './folder-in-server-to-save-projektbild/'+req.body.pname+'/'+projectPicture.name
// PATH FOR TEST/LIVE SERVER
// var projectPicturePath = to-be-defined // var projectPicturePath = to-be-defined
}
}
var projectTerm = req.body.termForm + " - " + req.body.termTo var projectTerm = req.body.termForm + " - " + req.body.termTo
var projectOverviewData = { var projectOverviewData = {
...@@ -197,18 +220,9 @@ module.exports = function (app) { ...@@ -197,18 +220,9 @@ module.exports = function (app) {
leader_email: req.body.leaderEmail leader_email: req.body.leaderEmail
} }
// raise error if limit is exceeded
if (projectLogo && projectLogo.size === pictSizeLimit) {
req.flash('error', 'Projektlogo exceeds 1 MB');
res.redirect('/addprojectoverview');
}
if (projectPicture && projectPicture.size === pictSizeLimit) {
req.flash('error', 'Projektbild exceeds 1 MB');
res.redirect('/addprojectoverview');
}
// save pictures // save pictures
projectLogo.mv('./folder-in-server-to-save-projektlogo/'+req.body.pname+'/'+projectLogo.name, function(err) { if (projectLogo) {
projectLogo.mv(projectLogoPath, function(err) {
if (err) { if (err) {
console.error(err) console.error(err)
res.status(500).render(lang+'/500', { res.status(500).render(lang+'/500', {
...@@ -216,7 +230,9 @@ module.exports = function (app) { ...@@ -216,7 +230,9 @@ module.exports = function (app) {
}) })
} }
}); });
projectPicture.mv('./folder-in-server-to-save-projektbild/'+req.body.pname+'/'+projectPicture.name, function(err) { }
if (projectPicture) {
projectPicture.mv(projectPicturePath, function(err) {
if (err) { if (err) {
console.error(err) console.error(err)
res.status(500).render(lang+'/500', { res.status(500).render(lang+'/500', {
...@@ -224,6 +240,7 @@ module.exports = function (app) { ...@@ -224,6 +240,7 @@ module.exports = function (app) {
}) })
} }
}); });
}
/* RS: Temporary solution while Project DB is still in early phase. /* RS: Temporary solution while Project DB is still in early phase.
When User DB and Project DB are integrated and quite stabil, this operation should be done in 1 transaction. When User DB and Project DB are integrated and quite stabil, this operation should be done in 1 transaction.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment