Skip to content

Commit d828228

Browse files
author
Athithyaa Selvam
committed
documents uploads will use HDFSfileUploadHandler when task_server is on
1 parent 488750b commit d828228

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

desktop/core/src/desktop/settings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ def is_oidc_configured():
659659
file_upload_handlers = []
660660
if is_chunked_fileuploader_enabled():
661661
file_upload_handlers = [
662-
'hadoop.fs.upload.FineUploaderChunkedUploadHandler',
662+
'hadoop.fs.upload.CustomDelegatingUploadHandler',
663663
'django.core.files.uploadhandler.MemoryFileUploadHandler',
664664
'django.core.files.uploadhandler.TemporaryFileUploadHandler',
665665
]

desktop/libs/hadoop/src/hadoop/fs/upload.py

+35
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,41 @@ def close(self):
221221
self._file.close()
222222

223223

224+
class CustomDelegatingUploadHandler(FileUploadHandler):
225+
"""
226+
Delegates the upload handling based on the request URL.
227+
228+
When the request URL starts with "/desktop/api2/doc/import" (indicating a document
229+
import), delegate all processing to HDFSfileUploadHandler.
230+
Otherwise, delegate to FineUploaderChunkedUploadHandler.
231+
"""
232+
233+
def __init__(self, request, *args, **kwargs):
234+
super().__init__(request, *args, **kwargs)
235+
if request.path.startswith("/desktop/api2/doc/import"):
236+
self.delegate = HDFSfileUploadHandler(request)
237+
else:
238+
self.delegate = FineUploaderChunkedUploadHandler(request, *args, **kwargs)
239+
240+
def new_file(self, field_name, file_name, *args, **kwargs):
241+
try:
242+
if hasattr(self.delegate, 'new_file'):
243+
result = self.delegate.new_file(field_name, file_name, *args, **kwargs)
244+
except StopFutureHandlers:
245+
result = None
246+
return result
247+
248+
def receive_data_chunk(self, raw_data, start):
249+
if hasattr(self.delegate, 'receive_data_chunk'):
250+
return self.delegate.receive_data_chunk(raw_data, start)
251+
return raw_data
252+
253+
def file_complete(self, file_size):
254+
if hasattr(self.delegate, 'file_complete'):
255+
return self.delegate.file_complete(file_size)
256+
return None
257+
258+
224259
class FineUploaderChunkedUploadHandler(FileUploadHandler):
225260
"""
226261
A custom file upload handler for handling chunked uploads using FineUploader.

0 commit comments

Comments
 (0)