Explorar o código

[Filebrowser] Add config for upload a file in a filesystem (#3262)

Ayush Goyal %!s(int64=2) %!d(string=hai) anos
pai
achega
6a85a64a5f

+ 7 - 0
apps/filebrowser/src/filebrowser/conf.py

@@ -77,6 +77,13 @@ REMOTE_STORAGE_HOME = Config(
   default=None,
   help="Optionally set this if you want a different home directory path. e.g. s3a://gethue.")
 
+MAX_FILE_SIZE_UPLOAD_LIMIT = Config(
+  key="max_file_size_upload_limit",
+  default=-1,
+  type=int,
+  help=_('A limit on a file size (bytes) that can be uploaded to a filesystem. '
+          'A value of -1 means there will be no limit.'))
+
 FILE_DOWNLOAD_CACHE_CONTROL = Config(
   key="file_download_cache_control",
   type=str,

+ 8 - 4
apps/filebrowser/src/filebrowser/templates/listdir_components.mako

@@ -2036,10 +2036,14 @@ else:
         });
 
         $("#fileUploader").on('fb:updatePath', function (e, options) {
-          const uploadingToOzone = self.currentPath().startsWith("ofs://");          
-          if (uploadingToOzone && UPLOAD_CHUNK_SIZE) {
-            uploader.setOption('sizeLimit', UPLOAD_CHUNK_SIZE);
-          }  
+          const uploadingToOzone = self.currentPath().startsWith("ofs://");
+          const ozoneSizeLimit = Math.min(
+            ...[UPLOAD_CHUNK_SIZE, MAX_FILE_SIZE_UPLOAD_LIMIT].filter(Number.isFinite)
+          );
+          const newSizeLimit = uploadingToOzone ? ozoneSizeLimit : MAX_FILE_SIZE_UPLOAD_LIMIT;
+          if (newSizeLimit) {
+            uploader.setOption('sizeLimit', newSizeLimit);
+          }
           uploader.setParams({
             dest: options.dest,
             fileFieldLabel: "hdfs_file"

+ 4 - 0
desktop/conf.dist/hue.ini

@@ -1628,6 +1628,10 @@ submit_to=True
 # Optionally set this to control the caching strategy for files download
 ## file_download_cache_control=no-store, no-cache, max-age=0, must-revalidate, proxy-revalidate
 
+# A limit on a file size (bytes) that can be uploaded to a filesystem.
+# A value of -1 means there will be no limit.
+## max_file_size_upload_limit=-1
+
 ###########################################################################
 # Settings to configure Pig
 ###########################################################################

+ 4 - 0
desktop/conf/pseudo-distributed.ini.tmpl

@@ -1611,6 +1611,10 @@
   # Optionally set this to control the caching strategy for files download
   ## file_download_cache_control=no-store, no-cache, max-age=0, must-revalidate, proxy-revalidate
 
+  # A limit on a file size (bytes) that can be uploaded to a filesystem.
+  # A value of -1 means there will be no limit.
+  ## max_file_size_upload_limit=-1
+
 
 ###########################################################################
 # Settings to configure Pig

+ 3 - 2
desktop/core/src/desktop/templates/global_js_constants.mako

@@ -29,7 +29,7 @@
   from dashboard.conf import HAS_SQL_ENABLED
   from hadoop.conf import UPLOAD_CHUNK_SIZE
   from jobbrowser.conf import ENABLE_HISTORY_V2
-  from filebrowser.conf import SHOW_UPLOAD_BUTTON, REMOTE_STORAGE_HOME
+  from filebrowser.conf import SHOW_UPLOAD_BUTTON, REMOTE_STORAGE_HOME, MAX_FILE_SIZE_UPLOAD_LIMIT
   from indexer.conf import ENABLE_NEW_INDEXER
   from libsaml.conf import get_logout_redirect_url, CDP_LOGOUT_URL
   from metadata.conf import has_catalog, has_readonly_catalog, has_optimizer, has_workload_analytics, OPTIMIZER, get_optimizer_url, \
@@ -137,7 +137,8 @@
 
   window.SHOW_NOTEBOOKS = '${ SHOW_NOTEBOOKS.get() }' === 'True'
   window.SHOW_UPLOAD_BUTTON = '${ hasattr(SHOW_UPLOAD_BUTTON, 'get') and SHOW_UPLOAD_BUTTON.get() }' === 'True'
-  window.UPLOAD_CHUNK_SIZE = '${ UPLOAD_CHUNK_SIZE.get() }';
+  window.UPLOAD_CHUNK_SIZE = ${ UPLOAD_CHUNK_SIZE.get() };
+  window.MAX_FILE_SIZE_UPLOAD_LIMIT = ${ MAX_FILE_SIZE_UPLOAD_LIMIT.get() if hasattr(MAX_FILE_SIZE_UPLOAD_LIMIT, 'get') and MAX_FILE_SIZE_UPLOAD_LIMIT.get() >= 0 else 'undefined' };
 
   window.IS_MULTICLUSTER_ONLY = '${ IS_MULTICLUSTER_ONLY.get() }' === 'True';
   window.IS_K8S_ONLY = '${ IS_K8S_ONLY.get() }' === 'True';