Skip to content

Commit 2d0748e

Browse files
committed
Added deserializer for Bytes field
1 parent 66f1617 commit 2d0748e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

labthings/server/fields.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Marshmallow fields
22
from marshmallow import ValidationError
3+
4+
from base64 import b64decode
5+
36
from marshmallow.fields import (
47
Field,
58
Raw,
@@ -75,3 +78,11 @@ def _validate(self, value):
7578

7679
if value is None or value == b"":
7780
raise ValidationError("Invalid value")
81+
82+
def _deserialize(self, value, attr, data, **kwargs):
83+
if isinstance(value, bytes):
84+
return value
85+
if isinstance(value, str):
86+
return b64decode(value)
87+
else:
88+
raise self.make_error("invalid", input=value)

0 commit comments

Comments
 (0)