rename and resize file before uploading

piece_demandeur = request.FILES['piece']
fs = FileSystemStorage(location='media/demande-upload/')
filename =, piece_demandeur)


I use this code in my views for uploading file with a model form. It works correctly But I would like to know how to rename and decrease size file (if file is greater than 200 Ko) before uploading.

I need your help.

Django can’t do anything like this because Django doesn’t have the file until after it’s uploaded.

It might be possible to find some JavaScript that may be able to do this in the browser - but from what I know of the upload process, I kind of doubt it. (In either case, this isn’t a Django issue.)