1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-26 00:38:10 +00:00

The upload interfaces allow user to choose an image type

This commit is contained in:
Julien Duponchelle 2015-03-07 13:52:40 +01:00
parent 1b68a54234
commit d126db1fe9
2 changed files with 12 additions and 3 deletions

View File

@ -55,9 +55,13 @@ class UploadHandler:
response.redirect("/upload") response.redirect("/upload")
return return
destination_path = os.path.join(UploadHandler.image_directory(), data["file"].filename) if data["type"] not in ["IOU", "QEMU", "IOS"]:
raise HTTPForbidden("You are not authorized to upload this kind of image {}".format(data["type"]))
destination_dir = os.path.join(UploadHandler.image_directory(), data["type"])
destination_path = os.path.join(destination_dir, data["file"].filename)
try: try:
os.makedirs(UploadHandler.image_directory(), exist_ok=True) os.makedirs(destination_dir, exist_ok=True)
with open(destination_path, "wb+") as f: with open(destination_path, "wb+") as f:
chunk = data["file"].file.read() chunk = data["file"].file.read()
f.write(chunk) f.write(chunk)

View File

@ -2,7 +2,12 @@
{% 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">
File: <input type="file" name="file" /> File: <input type="file" name="file" /><br>
Image type: <select name="type" />
<option value="IOU">IOU</option>
<option value="IOS">IOS</option>
<option value="QEMU">Qemu</option>
</select>
<br /> <br />
<br /> <br />
<input type="submit" value="Upload" /> <input type="submit" value="Upload" />