@detail_route(methods=['put'], parser_classes=[FileUploadParser])def avatar(self, request, pk=None):
file = request.data.get('file', None)
if not file:
print('f')
return Response(status=status.HTTP_400_BAD_REQUEST)
user = request.user
user.avatar_image.save(file.name, file)
user.save(update_fields={'avatar_image'})
generate_all_aliases(user.avatar_image, include_global=False)
return Response(AuthenticatedUserSerializer(request.user).data)
输入图片描述
尝试使用request. files .get()方法从request读取文件file = request.FILES.get('blogPhotos')