What is the best way to sanitize uploaded filenames in Django?

I tried using slugify however it made too many changes to the original filename, such as removing spaces joining the file extension to the rest of the name. I'd like to simply ensure that names are safe: 1. Not too long and 2. Prevent any attacks that can be carried out using the file's name(such as path traversal).

My app allows users to upload files(files are uploaded to DigitalOcean Spaces via my app) and filenames are stored using models.py/

Вернуться на верх