MCPcopy
hub / github.com/django/django / SimpleUploadedFile

Class SimpleUploadedFile

django/core/files/uploadedfile.py:131–155  ·  view source on GitHub ↗

A simple representation of a file, which just has content, size, and a name.

Source from the content-addressed store, hash-verified

129
130
131class SimpleUploadedFile(InMemoryUploadedFile):
132 """
133 A simple representation of a file, which just has content, size, and a
134 name.
135 """
136
137 def __init__(self, name, content, content_type="text/plain"):
138 content = content or b""
139 super().__init__(
140 BytesIO(content), None, name, content_type, len(content), None, None
141 )
142
143 @classmethod
144 def from_dict(cls, file_dict):
145 """
146 Create a SimpleUploadedFile object from a dictionary with keys:
147 - filename
148 - content-type
149 - content
150 """
151 return cls(
152 file_dict["filename"],
153 file_dict["content"],
154 file_dict.get("content-type", "text/plain"),
155 )

Callers 15

test_file_modeMethod · 0.90
test_readonly_rootMethod · 0.90
test_not_a_directoryMethod · 0.90
test_filesMethod · 0.90
test_filefield_readMethod · 0.90
test_filefield_writeMethod · 0.90
test_filefield_reopenMethod · 0.90
test_filesMethod · 0.90
test_full_clearMethod · 0.90
test_file_field_dataMethod · 0.90

Calls

no outgoing calls

Tested by 15

test_file_modeMethod · 0.72
test_readonly_rootMethod · 0.72
test_not_a_directoryMethod · 0.72
test_filesMethod · 0.72
test_filefield_readMethod · 0.72
test_filefield_writeMethod · 0.72
test_filefield_reopenMethod · 0.72
test_filesMethod · 0.72
test_full_clearMethod · 0.72
test_file_field_dataMethod · 0.72