python - Google Glass Tile insert Image from dataURL -


i writing glassware application in python using django, , have dataurl want insert image glass tile. tried inserting url image:

dataurl = canvas_file.value() //just extracting value of dataurl django form  tile = {         "html": "<img src={0}>".format(dataurl),         "speakabletype":"description.",         "speakabletext":message,         "menuitems": [ { "action":"read_aloud"}, ],         "notification": {         "level": "default"          }         }  service.timeline().insert(body=tile).execute() 

but data url long (so long browsers refuse navigate it), , glass doesn't want load image source. there way encode data url in python can insert media attachment?

data uris base64 encoded images.

for example, in image:

<img src="data:image/png;base64,ivborw0kggoaaaansuheugaaaaua aaafcayaaacnbyblaaaaheleqvqi12p4//8/w38giaxdibke0dhxgljnbaao 9txl0y4ohwaaaabjru5erkjggg==" alt="red dot" /> 

this base64 data image:

ivborw0kggoaaaansuheugaaaaua aaafcayaaacnbyblaaaaheleqvqi12p4//8/w38giaxdibke0dhxgljnbaao 9txl0y4ohwaaaabjru5erkjggg== 

once have that, converting base64 section of data uri binary stream attachment pretty straight forward:

import base64 import io  apiclient import errors apiclient.http import mediaiobaseupload  ...  timeline_item = {'text': 'hello world'} media_body =  mediaiobaseupload(io.bytesio(base64.b64decode('ivborw0kggoaaaansuheugaaaauaaaafcayaaacnbyblaaaaheleqvqi12p4//8/w38giaxdibke0dhxgljnbaao9txl0y4ohwaaaabjru5erkjggg==')), mimetype="image/png", resumable=true)  service.timeline().insert(body=timeline_item, media_body=media_body).execute() 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -