|
|
@@ -21,6 +21,7 @@ Classes for a custom upload handler to stream into S3.
|
|
|
See http://docs.djangoproject.com/en/1.9/topics/http/file-uploads/
|
|
|
"""
|
|
|
|
|
|
+import os
|
|
|
import logging
|
|
|
import unicodedata
|
|
|
from io import BytesIO as stream_io
|
|
|
@@ -34,6 +35,7 @@ from aws.s3.s3fs import S3FileSystemException
|
|
|
from desktop.conf import TASK_SERVER_V2
|
|
|
from desktop.lib.exceptions_renderable import PopupException
|
|
|
from desktop.lib.fsmanager import get_client
|
|
|
+from filebrowser.conf import RESTRICT_FILE_EXTENSIONS
|
|
|
from filebrowser.utils import calculate_total_size, generate_chunks
|
|
|
|
|
|
DEFAULT_WRITE_SIZE = 1024 * 1024 * 128 # TODO: set in configuration (currently 128 MiB)
|
|
|
@@ -156,9 +158,16 @@ class S3FileUploadHandler(FileUploadHandler):
|
|
|
|
|
|
def new_file(self, field_name, file_name, *args, **kwargs):
|
|
|
if self._is_s3_upload():
|
|
|
+ LOG.info('Using S3FileUploadHandler to handle file upload.')
|
|
|
+
|
|
|
+ _, file_type = os.path.splitext(file_name)
|
|
|
+ if RESTRICT_FILE_EXTENSIONS.get() and file_type.lower() in [ext.lower() for ext in RESTRICT_FILE_EXTENSIONS.get()]:
|
|
|
+ err_message = f'Uploading files with type "{file_type}" is not allowed. Hue is configured to restrict this type.'
|
|
|
+ LOG.error(err_message)
|
|
|
+ raise Exception(err_message)
|
|
|
+
|
|
|
super(S3FileUploadHandler, self).new_file(field_name, file_name, *args, **kwargs)
|
|
|
|
|
|
- LOG.info('Using S3FileUploadHandler to handle file upload.')
|
|
|
self.target_path = self._fs.join(self.key_name, file_name)
|
|
|
|
|
|
try:
|