Limit file size during upload

Fix #86
This commit is contained in:
Julien Duponchelle 2015-06-12 10:10:46 +02:00
parent 04aac2f3dc
commit 4e16433a08
2 changed files with 22 additions and 2 deletions

View File

@ -1,6 +1,9 @@
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script>
{% block script %}{% endblock %}
</script>
<title>GNS3 Server</title> <title>GNS3 Server</title>
</head> </head>
<body> <body>

View File

@ -1,8 +1,25 @@
{% extends "layout.html" %} {% extends "layout.html" %}
{% block script %}
function onSubmit() {
if (document.getElementById("uploadInput").files == undefined) {
//OLD browser
return true;
}
max_size = 200;
var file = document.getElementById("uploadInput").files[0];
var size = Math.round(file.size / 1000000);
if (size > max_size) {
alert("The file is too big (" + size + " MB). The max upload size is " + max_size + " MB. Please Upload your file with the GNS3 GUI");
return false;
}
return true;
}
{% endblock %}
{% block body %} {% block body %}
<h1>Select & Upload an image for GNS3</h1> <h1>Select & Upload an image for GNS3</h1>
<form enctype="multipart/form-data" action="/upload" method="post"> <form enctype="multipart/form-data" action="/upload" method="post" onSubmit="return onSubmit()">
File path: <input type="file" name="file" /><br> File path: <input type="file" name="file" id="uploadInput" /><br>
File type: <select name="type" /> File type: <select name="type" />
<option value="IOU">IOU</option> <option value="IOU">IOU</option>
<option value="IOURC">IOU licence (iourc)</option> <option value="IOURC">IOU licence (iourc)</option>