[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
|
originServer = .di.uoa.gr
|
||||||
post.allowed = /upload,/upload/
|
post.allowed = /upload,/upload/
|
||||||
ssl = false
|
ssl = false
|
||||||
localPath = false
|
localPath = true
|
||||||
|
# photo size in KB
|
||||||
|
photo.size = 200
|
||||||
|
|
|
@ -9,7 +9,7 @@ var app = express();
|
||||||
var http = null;
|
var http = null;
|
||||||
|
|
||||||
if(properties.get('ssl')) {
|
if(properties.get('ssl')) {
|
||||||
http = require("https");
|
http = require("https");
|
||||||
} else {
|
} else {
|
||||||
http = require("http");
|
http = require("http");
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ var auth = properties.get('userInfoUrl');
|
||||||
var originServer = properties.get('originServer');
|
var originServer = properties.get('originServer');
|
||||||
var allowPostRequests = properties.get('post.allowed').split(',');
|
var allowPostRequests = properties.get('post.allowed').split(',');
|
||||||
var localPath = properties.get('localPath');
|
var localPath = properties.get('localPath');
|
||||||
|
var maxsize = properties.get('photo.size')*1024;
|
||||||
|
|
||||||
var storage = multer.diskStorage({
|
var storage = multer.diskStorage({
|
||||||
destination: function (req, file, cb) {
|
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");
|
console.error("No proper file type");
|
||||||
res.status(500).send(getResponse(500, "No proper file type"));
|
res.status(500).send(getResponse(500, "No proper file type"));
|
||||||
} else {
|
} else {
|
||||||
//send file
|
|
||||||
res.download(filepath);
|
res.download(filepath);
|
||||||
}
|
}
|
||||||
deleteFile(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"));
|
res.status(500).send(getResponse(500, "No image file type"));
|
||||||
deleteFile(filepath);
|
deleteFile(filepath);
|
||||||
}
|
}
|
||||||
|
else if (file.size > maxsize) {
|
||||||
|
res.status(500).send(getResponse(500, "Exceeds file size limit"));
|
||||||
|
deleteFile(filepath);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
http.get(auth+token, function (resp) {
|
http.get(auth+token, function (resp) {
|
||||||
var responseString = "";
|
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);
|
console.log("Listening on port %s...", server.address().port);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue