Created
January 8, 2013 04:39
-
-
Save josephsu/4481205 to your computer and use it in GitHub Desktop.
decode Data URI to mime and data parts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
def decodeDataUri(uristr): | |
comma = uristr.find(',') | |
urihead = uristr.find('data:') | |
if urihead is None or comma is None: | |
return None | |
headpart = uristr[urihead + 5:comma] | |
firstsep = headpart.find(';') | |
if firstsep is None: | |
firstsep = len(firstsep) | |
mimetype = headpart[0:firstsep] | |
b64data = uristr[(comma + 1):] | |
rawdata = base64.b64decode(b64data) | |
return ( mimetype, rawdata ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment