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
{{ message }}
Repository navigation
How to store filename returned by storage for sized images? #179
The issue is that the filesystem returns the new filename as the return from save, and I need to try and get VersatileImageFieldWarmer to save these filenames for each sized image rendition to a meta field or something so it can be used for the filelocations returned by DRF.
Is there a way to accomplish this natively? Or will I need to override a class somewhere in my code for this usecase?
I worked around this problem for now by overriding the django-hashedfilenamestorage Storage class and overwriting their _get_content_name fuction with an exclusion for the __sized__ dir. While this works... I'm not sure it's a great solution. There may be storages where this isn't an option as well.
For anyone that hits this when using these two in combination, you can add this override for the mentioned fuction for now:
def_get_content_name(self, name, content, chunk_size=None):
""" Gets the filename based on file content. :param name: :param content: :param chunk_size: :return: """dir_name, file_name=os.path.split(name)
file_ext=os.path.splitext(file_name)[1].lower()
if'__sized__'notindir_name:
file_root=self._compute_hash(content=content,
chunk_size=chunk_size)
else:
file_root=file_name# file_ext includes the dot.returnos.path.join(dir_name, file_root+file_ext)
Activity
Routhinator commentedon Feb 1, 2021
I worked around this problem for now by overriding the
django-hashedfilenamestorageStorage class and overwriting their_get_content_namefuction with an exclusion for the__sized__dir. While this works... I'm not sure it's a great solution. There may be storages where this isn't an option as well.For anyone that hits this when using these two in combination, you can add this override for the mentioned fuction for now: