We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ccef0a8 commit af880fcCopy full SHA for af880fc
adafruit_httpserver/request.py
@@ -94,6 +94,25 @@ def __init__(
94
self.content_type = content_type
95
self.content = content
96
97
+ @property
98
+ def content_bytes(self) -> bytes:
99
+ """
100
+ Content of the file as bytes.
101
+ It is recommended to use this instead of ``content`` as it will always return bytes.
102
+
103
+ Example::
104
105
+ file = request.form_data.files.get("uploaded_file")
106
107
+ with open(file.filename, "wb") as f:
108
+ f.write(file.content_bytes)
109
110
+ return (
111
+ self.content.encode("utf-8")
112
+ if isinstance(self.content, str)
113
+ else self.content
114
+ )
115
116
@property
117
def size(self) -> int:
118
"""Length of the file content."""
0 commit comments