diff --git a/mayan/apps/sources/api_views.py b/mayan/apps/sources/api_views.py index 9e598a2c7e..34d7badea1 100644 --- a/mayan/apps/sources/api_views.py +++ b/mayan/apps/sources/api_views.py @@ -116,6 +116,7 @@ class APIDocumentCreateView(generics.CreateAPIView): temporary_file.write(chunk) temporary_file.close() + self.request.FILES['file'].close() else: return Response({ 'status': 'error', @@ -129,7 +130,8 @@ class APIDocumentCreateView(generics.CreateAPIView): task_upload_document.apply_async(kwargs=dict( source_id=int(request.get('source')), - file_path=temporary_file.name, filename=request.get('filename', None), + file_path=temporary_file.name, + filename=request.get('filename', self.request.FILES['file'].name), use_file_name=request.get('use_file_name', False), document_type_id=int(request.get('document_type', 0)) or None, expand=request.get('expand', False), diff --git a/mayan/apps/sources/views.py b/mayan/apps/sources/views.py index 1e58a4c8e6..ad5215fc12 100644 --- a/mayan/apps/sources/views.py +++ b/mayan/apps/sources/views.py @@ -193,6 +193,7 @@ def upload_interactive(request, source_id=None, document_pk=None): temporary_file.write(chunk) temporary_file.close() + file_object.close() if isinstance(source, StagingFolderSource): if source.delete_after_upload: @@ -205,7 +206,8 @@ def upload_interactive(request, source_id=None, document_pk=None): task_upload_document.apply_async(kwargs=dict( source_id=source.pk, - file_path=temporary_file.name, filename=new_filename, + file_path=temporary_file.name, + filename=new_filename or file_object.name, use_file_name=form.cleaned_data.get('use_file_name', False), document_type_id=document_type_id, expand=expand,