0

I know how to show picture as a page from memory just using like this:

import cStringIO

mStream = cStringIO.StringIO(picBin)

return HttpResponse(mStream.getvalue(),"image/jpg")

But what if I don't want to show the picture as a page, instead I want to show it within a page, say using in HTML, does someone has an idea what I should set the "src" if the picture is loaded from memory?

JoeG
  • 12,994
  • 1
  • 38
  • 63
Wally Yu
  • 51
  • 1
  • 6

1 Answers1

1

You'll need to base-64 encode the image contents into a Data URI:

data_uri = 'data:image/jpg;base64,'
data_uri += mStream.getvalue().encode('base64').replace('\n', '')

Now you can shove data_uri into the src attribute of an image.

Blender
  • 289,723
  • 53
  • 439
  • 496