Closed sampaccoud closed 1 year ago
I've had exactly the same issue in my Django project with django-filer file manager. Error is caused by this SQL query:
INSERT INTO "easy_thumbnails_thumbnail" ("storage_hash", "name", "modified", "source_id") VALUES ('f9bde26a1556cd667f742bd34ec7c55e', 'filer_public_thumbnails/filer_public/1e/ec/1eec4da6-782c-4251-a65d-1624827036ca/melchior_wankowicz_przekazuje_weteranowi_powstania_styczniowego_mamertowi_wandalliemu_klucz_do_domu_w_osiedlu_zasluzonych_im_aleksandry_pilsudskiej_1936_fot_polona.jpg__80x80_q85_crop_subsampling-2.jpg', '2022-01-25T20:25:27.332494+00:00'::timestamptz, 956) RETURNING "easy_thumbnails_thumbnail"."id"
This is my solution:
filer.utils.generate_filename.randomized
FILER_STORAGES = {
'public': {
'main': {
'UPLOAD_TO': 'appname.utils.filer_name_validation'
}
},
'private': {
'main': {
'UPLOAD_TO': 'appname.utils.filer_name_validation'
}
}
}
randomized
function for cutting too long names:
from filer.utils.generate_filename import randomized
def filer_name_validation(instance, filename): name = randomized(instance, filename) extension = name.split('.')[-1] name = name[:100] name = name[:len(name) - len(extension) - 1] + '.' + extension return name
That's it. I've chosen to cut the string to 100 characters, because you have to consider the absolute path in `name`,
so `path` + `filename[:100]` + `extension` should be enough to fit `max_lenght=255` in filer model.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This will now be closed due to inactivity, but feel free to reopen it.
When the source file name is too long, I get a database error that the thumbnail name is too long:
I tried configuring the THUMBNAIL_NAMER option to shorten the thumbnails name but Django filer overrides the get_thumbnail_name method and breaks this feature (known issue https://github.com/django-cms/django-filer/issues/1093).
I don't really care how my thumbnails are named but we should make sure it does not cause a database error.
I don't know what is the solution for this:
get_thumbnail_name
method but how?