Hi all,
I am faced with an edge case when using a form FileField. On my webpage, the user uploads a mandatory excel file and, optionally, a zip file full of pictures. So my form has two FileFields. Upon submission, both the excel file and zip file (if uploaded) are processed in a background task and saved to Amazon S3. I have custom validators that make sure that the extensions of both files match Excel and zip respectively.
Whilst this setup behaves as expected when a user uploads files, it does not work when a user uploads folders: in this case, if a user uploaded by mistake a folder in place of a zip file, the validation would pass since the file passed to it is None and the field is required=False. However, the processing would fail since my code that uploads to S3 expects a file, not a folder. Essentially the problem boils down to the FileField giving the file the value of None if a user drags a folder to it and uploads it, exhibiting therefore the same behaviour if the user uploads a folder or uploads nothing at all.
Is there a way to detect a folder upload programmatically?
Thanks,
Alberto