def put(self, request, *args, **kwargs):
'''
If there is a thumbnail, and it was sent as part of an
application/json payload, then we need to unpack a thumbnail
object payload and convert it to a Python ContentFile payload
instead. We use a try/catch because the optional nature means
we need to check using "if hasattr(request.data,'thumbnail'):"
as we as "if request.data['thumbnail']" and these are pretty
much mutually exclusive patterns. A try/pass make far more sense.
'''
try:
thumbnail = request.data['thumbnail']
# do we actually need to repack as ContentFile?
if thumbnail['name'] and thumbnail['base64']:
name = thumbnail['name']
encdata = thumbnail['base64']
proxy = ContentFile(base64.b64decode(encdata), name=name)
request.data['thumbnail'] = proxy
except:
pass
return super(UserProfileAPIView, self).put(request, *args, **kwargs)
评论列表
文章目录