Dear all,
I am currently writing an application where I upload many (i.e. 1000+) small images via a generic form (CreateView). With a small amount of files, it works without any problems. With an increasing number, I get the “Too many open files error”. Changing the limit of simultaneously opened files on OS level is not an option. So I adapted the UploadHandler as follows to closed the files after the upload:
class ClosingFileTemporaryFileUploadHandler(TemporaryFileUploadHandler):
def file_complete(self, *args, **kwargs):
f = super().file_complete(*args, **kwargs)
f.close()
return f
Now, I am facing the problem that the form validation fails “Upload a valid image. The file you uploaded was either not an image or a corrupted image.”. I think I need adapt the validators in a way they first re-open the files, do the validation and close it again. The question is: How and where to do this optimally, i.e. in an iterative way over all received files? Or is there a more generic approach? I have the feeling that I am overcomplicating the thing.
I am using Django version 4.1.3, Python 3.10.8, Debian
Thanks a lot for your support.
Best regards
Jens