Unzip and delete zip files after upload; validate upload file suffix

This commit is contained in:
Daniel Markstedt 2021-09-23 08:45:46 -07:00
parent 991d1232f9
commit cda975a66f
3 changed files with 10 additions and 1 deletions

View File

@ -12,3 +12,4 @@ zope.event==4.5.0
zope.interface==5.1.2
protobuf==3.17.3
pydrop==0.0.6
zipfile

View File

@ -180,6 +180,7 @@
<script type="application/javascript">
Dropzone.options.dropper = {
paramName: 'file',
acceptedFiles: '{{valid_file_suffix}}'
chunking: true,
forceChunking: true,
url: '/files/upload',

View File

@ -526,7 +526,14 @@ def upload_file():
log.debug(f"Chunk {current_chunk + 1} of {total_chunks} "
f"for file {file.filename} completed.")
return make_response(("File upload successful!", 200))
if file.filename.endswith("zip"):
from zipfile import ZipFile
with ZipFile(file_path, 'r') as zip:
zip.extractall()
delete_file(file_path)
return make_response(("File upload and unzip successful!", 200))
else:
return make_response(("File upload successful!", 200))
@app.route("/files/create", methods=["POST"])