I have an image file stream in Python:
\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x04\x87...
How do I convert this to a data URI ?
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAU...'
Encode it in base64, then remove the newlines.
>>> '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x04\x87...'.encode('base64').replace('\n', '') 'iVBORw0KGgoAAAANSUhEUgAABI....'