def file_upload_view_verify(request):
 form_data = request.POST.copy()
 form_data.update(request.FILES)
 for (key, value) in form_data.items():
  if key.endswith(u'_hash'):
   continue
  if ((key + u'_hash') not in form_data):
   continue
  submitted_hash = form_data[(key + u'_hash')]
  if isinstance(value, UploadedFile):
   new_hash = hashlib.sha1(value.read()).hexdigest()
  else:
   new_hash = hashlib.sha1(force_bytes(value)).hexdigest()
  if (new_hash != submitted_hash):
   return HttpResponseServerError()
 largefile = request.FILES[u'file_field2']
 obj = FileModel()
 obj.testfile.save(largefile.name, largefile)
 return HttpResponse(u'')

def file_upload_view_verify ( request ) : form_data = request . POST . copy ( ) form_data . update ( request . FILES ) for ( key , value ) in form_data . items ( ) : if key . endswith ( u'_hash' ) : continue if ( ( key + u'_hash' ) not in form_data ) : continue submitted_hash = form_data [ ( key + u'_hash' ) ] if isinstance ( value , UploadedFile ) : new_hash = hashlib . sha1 ( value . read ( ) ) . hexdigest ( ) else : new_hash = hashlib . sha1 ( force_bytes ( value ) ) . hexdigest ( ) if ( new_hash != submitted_hash ) : return HttpResponseServerError ( ) largefile = request . FILES [ u'file_field2' ] obj = FileModel ( ) obj . testfile . save ( largefile . name , largefile ) return HttpResponse ( u'' )
use the sha digest hash to verify the uploaded contents .