mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-04 03:27:12 -05:00 
			
		
		
		
	Provide utf-8 encoded content-disposition field to address the issues in the firefox when downloading files
Fixes #56
This commit is contained in:
		
							parent
							
								
									a10d331296
								
							
						
					
					
						commit
						940d056657
					
				@ -5,6 +5,8 @@ import uuid
 | 
				
			|||||||
import zipfile
 | 
					import zipfile
 | 
				
			||||||
from datetime import datetime
 | 
					from datetime import datetime
 | 
				
			||||||
from time import mktime
 | 
					from time import mktime
 | 
				
			||||||
 | 
					from urllib.parse import quote_plus
 | 
				
			||||||
 | 
					from unicodedata import normalize
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from django.conf import settings
 | 
					from django.conf import settings
 | 
				
			||||||
from django.db.models import Count, Max, Case, When, IntegerField
 | 
					from django.db.models import Count, Max, Case, When, IntegerField
 | 
				
			||||||
@ -62,7 +64,6 @@ from .serialisers import (
 | 
				
			|||||||
    BulkDownloadSerializer
 | 
					    BulkDownloadSerializer
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
logger = logging.getLogger("paperless.api")
 | 
					logger = logging.getLogger("paperless.api")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -220,8 +221,16 @@ class DocumentViewSet(RetrieveModelMixin,
 | 
				
			|||||||
            file_handle = GnuPG.decrypted(file_handle)
 | 
					            file_handle = GnuPG.decrypted(file_handle)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        response = HttpResponse(file_handle, content_type=mime_type)
 | 
					        response = HttpResponse(file_handle, content_type=mime_type)
 | 
				
			||||||
        response["Content-Disposition"] = '{}; filename="{}"'.format(
 | 
					        # Firefox is not able to handle unicode characters in filename field
 | 
				
			||||||
            disposition, filename)
 | 
					        # RFC 5987 addresses this issue
 | 
				
			||||||
 | 
					        # see https://datatracker.ietf.org/doc/html/rfc5987#section-4.2
 | 
				
			||||||
 | 
					        filename_normalized = normalize("NFKD", filename)\
 | 
				
			||||||
 | 
					            .encode('ascii', 'ignore')
 | 
				
			||||||
 | 
					        filename_encoded = quote_plus(filename)
 | 
				
			||||||
 | 
					        content_disposition = f'{disposition}; ' \
 | 
				
			||||||
 | 
					                              f'filename="{filename_normalized}"; ' \
 | 
				
			||||||
 | 
					                              f'filename*=utf-8\'\'{filename_encoded}'
 | 
				
			||||||
 | 
					        response["Content-Disposition"] = content_disposition
 | 
				
			||||||
        return response
 | 
					        return response
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_metadata(self, file, mime_type):
 | 
					    def get_metadata(self, file, mime_type):
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user