MCPcopy
hub / github.com/django/django / file_upload_view_verify

Function file_upload_view_verify

tests/file_uploads/views.py:36–61  ·  view source on GitHub ↗

Use the sha digest hash to verify the uploaded contents.

(request)

Source from the content-addressed store, hash-verified

34
35
36def file_upload_view_verify(request):
37 """
38 Use the sha digest hash to verify the uploaded contents.
39 """
40 form_data = request.POST.copy()
41 form_data.update(request.FILES)
42
43 for key, value in form_data.items():
44 if key.endswith("_hash"):
45 continue
46 if key + "_hash" not in form_data:
47 continue
48 submitted_hash = form_data[key + "_hash"]
49 if isinstance(value, UploadedFile):
50 new_hash = hashlib.sha1(value.read()).hexdigest()
51 else:
52 new_hash = hashlib.sha1(value.encode()).hexdigest()
53 if new_hash != submitted_hash:
54 return HttpResponseServerError()
55
56 # Adding large file to the database should succeed
57 largefile = request.FILES["file_field2"]
58 obj = FileModel()
59 obj.testfile.save(largefile.name, largefile)
60
61 return HttpResponse()
62
63
64def file_upload_unicode_name(request):

Callers

nothing calls this directly

Calls 9

HttpResponseClass · 0.90
FileModelClass · 0.70
copyMethod · 0.45
updateMethod · 0.45
itemsMethod · 0.45
readMethod · 0.45
encodeMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected