Skip to content

documents uploads will use HDFSfileUploadHandler when task_server is on #4044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion desktop/core/src/desktop/settings.py
Original file line number Diff line number Diff line change
@@ -660,7 +660,7 @@ def is_oidc_configured():
file_upload_handlers = []
if is_chunked_fileuploader_enabled():
file_upload_handlers = [
'hadoop.fs.upload.FineUploaderChunkedUploadHandler',
'hadoop.fs.upload.CustomDocumentsUploadHandler',
'django.core.files.uploadhandler.MemoryFileUploadHandler',
'django.core.files.uploadhandler.TemporaryFileUploadHandler',
]
2 changes: 1 addition & 1 deletion desktop/core/src/desktop/urls.py
Original file line number Diff line number Diff line change
@@ -165,7 +165,7 @@
re_path(r'^desktop/api2/user_preferences(?:/(?P<key>\w+))?/?$', desktop_api2.user_preferences, name="desktop.api2.user_preferences"),

re_path(r'^desktop/api2/doc/export/?$', desktop_api2.export_documents),
re_path(r'^desktop/api2/doc/import/?$', desktop_api2.import_documents),
re_path(r'^desktop/api2/doc/import/?$', desktop_api2.import_documents, name='import_documents'),

re_path(r'^desktop/api2/gist/create/?$', desktop_api2.gist_create),
re_path(r'^desktop/api2/gist/open/?$', desktop_api2.gist_get),
38 changes: 38 additions & 0 deletions desktop/libs/hadoop/src/hadoop/fs/upload.py
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@
from builtins import object

from django.core.files.uploadhandler import FileUploadHandler, SkipFile, StopFutureHandlers, StopUpload, UploadFileException
from django.urls import reverse
from django.utils.translation import gettext as _

import hadoop.cluster
@@ -221,6 +222,43 @@ def close(self):
self._file.close()


class CustomDocumentsUploadHandler(FileUploadHandler):
"""
Delegates the upload handling based on the request URL.

When the request URL starts with "/desktop/api2/doc/import" (indicating a document
import), delegate all processing to HDFSfileUploadHandler.
Otherwise, delegate to FineUploaderChunkedUploadHandler.
"""

def __init__(self, request, *args, **kwargs):
super().__init__(request, *args, **kwargs)
import_path = reverse('import_documents')

if request.path.startswith(import_path):
self.delegate = HDFSfileUploadHandler(request)
else:
self.delegate = FineUploaderChunkedUploadHandler(request, *args, **kwargs)

def new_file(self, field_name, file_name, *args, **kwargs):
try:
if hasattr(self.delegate, 'new_file'):
result = self.delegate.new_file(field_name, file_name, *args, **kwargs)
except StopFutureHandlers:
result = None
return result

def receive_data_chunk(self, raw_data, start):
if hasattr(self.delegate, 'receive_data_chunk'):
return self.delegate.receive_data_chunk(raw_data, start)
return raw_data

def file_complete(self, file_size):
if hasattr(self.delegate, 'file_complete'):
return self.delegate.file_complete(file_size)
return None


class FineUploaderChunkedUploadHandler(FileUploadHandler):
"""
A custom file upload handler for handling chunked uploads using FineUploader.