[Trunk|Services]: Upload Service: add file size limit 200KB.
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@56253 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
7b07addaf5
commit
7f6c98120e
|
@ -2,4 +2,6 @@ userInfoUrl = http://scoobydoo.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT
|
|||
originServer = .di.uoa.gr
|
||||
post.allowed = /upload,/upload/
|
||||
ssl = false
|
||||
localPath = false
|
||||
localPath = true
|
||||
# photo size in KB
|
||||
photo.size = 200
|
||||
|
|
|
@ -9,7 +9,7 @@ var app = express();
|
|||
var http = null;
|
||||
|
||||
if(properties.get('ssl')) {
|
||||
http = require("https");
|
||||
http = require("https");
|
||||
} else {
|
||||
http = require("http");
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ var auth = properties.get('userInfoUrl');
|
|||
var originServer = properties.get('originServer');
|
||||
var allowPostRequests = properties.get('post.allowed').split(',');
|
||||
var localPath = properties.get('localPath');
|
||||
var maxsize = properties.get('photo.size')*1024;
|
||||
|
||||
var storage = multer.diskStorage({
|
||||
destination: function (req, file, cb) {
|
||||
|
@ -73,7 +74,6 @@ app.post("/upload", upload.array("uploads[]", 12), function (req, res) {
|
|||
console.error("No proper file type");
|
||||
res.status(500).send(getResponse(500, "No proper file type"));
|
||||
} else {
|
||||
//send file
|
||||
res.download(filepath);
|
||||
}
|
||||
deleteFile(filepath);
|
||||
|
@ -93,6 +93,10 @@ app.post('/upload/:id', upload.single('photo'), (req, res) => {
|
|||
res.status(500).send(getResponse(500, "No image file type"));
|
||||
deleteFile(filepath);
|
||||
}
|
||||
else if (file.size > maxsize) {
|
||||
res.status(500).send(getResponse(500, "Exceeds file size limit"));
|
||||
deleteFile(filepath);
|
||||
}
|
||||
else {
|
||||
http.get(auth+token, function (resp) {
|
||||
var responseString = "";
|
||||
|
@ -163,7 +167,7 @@ app.delete('/delete/:filename', function (req, res) {
|
|||
}
|
||||
});
|
||||
|
||||
const server = app.listen(8000, function () {
|
||||
const server = app.listen(8001, function () {
|
||||
console.log("Listening on port %s...", server.address().port);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue