Fix #847: Use ASCII filename before upload to S3 to avoid playback issues

This commit is contained in:
Eliot Berriot 2019-06-10 14:33:46 +02:00
commit 2523108b6a
No known key found for this signature in database
GPG key ID: DD6965E2476E5C27
5 changed files with 43 additions and 5 deletions

View file

@ -1,13 +1,21 @@
import unicodedata
import slugify
from django.core.files.storage import FileSystemStorage
from storages.backends.s3boto3 import S3Boto3Storage
class ASCIIFileSystemStorage(FileSystemStorage):
def asciionly(name):
"""
Convert unicode characters in name to ASCII characters.
"""
return slugify.slugify(name, ok=slugify.SLUG_OK + ".", only_ascii=True)
class ASCIIFileSystemStorage(FileSystemStorage):
def get_valid_name(self, name):
name = unicodedata.normalize("NFKD", name).encode("ascii", "ignore")
return super().get_valid_name(name)
return super().get_valid_name(asciionly(name))
class ASCIIS3Boto3Storage(S3Boto3Storage):
def get_valid_name(self, name):
return super().get_valid_name(asciionly(name))