You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently banged my head against the wall for a while to figure out why files being uploaded from my site were being renamed with underscores and non-alphanumeric characters (like apostrophes) were being deleted. Turns out this is Django's fault, because their Storage.get_valid_name() method calls django.utils.text.get_valid_filename() to convert the filenames of every file uploaded.
This is all well and good if you're using ancient filesystems and long-dead browsers, but it's pointless in the modern age, and is more confusing than anything else.
However, this is a long-established default behavior, so simple changing it unilaterally is a bad idea. Thus, I propose a new boolean setting for django-storages, perhaps named STORAGES_MANGLE_FILENAMES, which defaults to True. Users can then set it to False to turn off automatic filename mangling.
This would be implemented as an override to the Storage.get_valid_name() method in each subclass of Storage defined by django-storages (probably just a few lines in BaseStorage). Something like this:
def get_valid_name(self, name):
if settings.STORAGES_MANGLE_FILENAMES:
return super().get_valid_name(name)
else:
return name
The text was updated successfully, but these errors were encountered:
@coredumperror , did you got anything to sort this out. I'm facing the same issue and i'm breaking my head around this. Let me know, if you found anything.
I couldn't recall for sure if I'd found a solution to this, but looking through my shop's code for these method names led me to a part of my code that calls django.utils.text.get_valid_filename() intentionally, to mangle the filename of an uploading file in the same way Django does, so our form code can do a proper comparison between the incoming file and all existing files in the S3 bucket.
So I think I just worked around this issue, rather than finding an actual fix.
I recently banged my head against the wall for a while to figure out why files being uploaded from my site were being renamed with underscores and non-alphanumeric characters (like apostrophes) were being deleted. Turns out this is Django's fault, because their
Storage.get_valid_name()
method callsdjango.utils.text.get_valid_filename()
to convert the filenames of every file uploaded.This is all well and good if you're using ancient filesystems and long-dead browsers, but it's pointless in the modern age, and is more confusing than anything else.
However, this is a long-established default behavior, so simple changing it unilaterally is a bad idea. Thus, I propose a new boolean setting for django-storages, perhaps named
STORAGES_MANGLE_FILENAMES
, which defaults toTrue
. Users can then set it toFalse
to turn off automatic filename mangling.This would be implemented as an override to the
Storage.get_valid_name()
method in each subclass of Storage defined by django-storages (probably just a few lines in BaseStorage). Something like this:The text was updated successfully, but these errors were encountered: