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 zope.interface==5.1.2
protobuf==3.17.3 protobuf==3.17.3
pydrop==0.0.6 pydrop==0.0.6
zipfile

View File

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

View File

@ -526,6 +526,13 @@ def upload_file():
log.debug(f"Chunk {current_chunk + 1} of {total_chunks} " log.debug(f"Chunk {current_chunk + 1} of {total_chunks} "
f"for file {file.filename} completed.") f"for file {file.filename} completed.")
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)) return make_response(("File upload successful!", 200))