I have implemented django-photologue and I am trying to return a base64 encoded image from my django view as following:
@api_view(('GET',))
def get_gallery(request, id):
gallery = Gallery.objects.get(id=id)
data = []
for photo in gallery.sample():
data.append(photo.image_url)
return Response(data)
for Response(data)
I get
["data:image/jpg;base64,iVBORw0KGgoAAAANSUhEUgAAAfQAAAFeCAIAAAD8M3pVAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ\nbWFn --string continues--"]
notice '\n'in the string
I am trying this (http://codebeautify.org/base64-to-image-converter) converter to see if I get the image back and it fails with the returned response.
If I change it to HttpResponse(data)
I get:
data:image/jpg;base64,iVBORw0KGgoAAAANSUhEUgAAAfQAAAFeCAIAAAD8M3pVAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ bWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG --string continuous--
notice '\n' is now gone. This result renders image when I try it in this converter.
What is the correct way of returning such base64 images from Django view? I am using angular2 frontend and I am confused what can be returned so that it can be handled on the frontend to render images.