[web2py] Re: GAE - Rendering uploaded Blob as jpeg image rather than as a string?

2012-02-24 Thread Massimo Di Pierro
You have two actions:

list_image() - returns an image (always image 1?)
ist_images() - returns the html page.

In the latter you can do:

View:
  {{extend 'layout.html'}}
  h3Display Jpeg Images/h3
  table border=1
tr
   thImage Title/th
   thImage Blob/th
/tr
{{for img in images:}}
tr
td{{ =img.title }}/td
td{{=img.image_blob }}//td
tdimg src={{=URL('list_image',args=img.id)}} //td
!-- added this line --
/tr
{{pass}}
  /table

Anyway, I have the impression you are reinventing the wheel a little.
Did you look into upload field and the downloadaction? They are
designed to do what you need.

On Feb 23, 11:28 pm, BrendanC bren...@gmail.com wrote:
 OK - Quick follow up here - I was able to display an blob image using the
 call:

 def list_image():

    myid = 1    # test
     image=db(db.xim.id==myid).select(orderby=db.xim.title)
     response.headers['Content-Type']='image/jpeg'

     mystream = image.image_blob
     return mystream

 However this renders an image in separate page with no additional info.
 What I really want is to display the stream as part of a template (within
  a table) with additional related image info (Title, Comments etc). IOW I
 want to embed the stream within an html template, rather than as a
 separate, standalone file.

 Am I missing piece of the puzzle here?


[web2py] Re: GAE - Rendering uploaded Blob as jpeg image rather than as a string?

2012-02-24 Thread Wikus van de Merwe
You kind of do :) There is no way to embed streams in HTML directly. You 
need a separate function showing a single image by id (e.g. /show_image/id) 
and build a list with links to that function in the list_image view.

{{for img in images:}}
  tr
{{= TD(img.title) }}
{{= TD(IMG(_src=URL(show_image, args=img.id), _alt=img.title)) }}
  /tr
{{pass}}



[web2py] Re: GAE - Rendering uploaded Blob as jpeg image rather than as a string?

2012-02-23 Thread Massimo Di Pierro
you need to set the

response.header['Content-type']='image/jpeg'

else the browser does not know what to do with the file.


On Feb 23, 2:23 pm, BrendanC bren...@gmail.com wrote:
 I uploaded a small (1mb)  jpeg image to my local dev app server. In this
 case the blob goes in the image file and is stored as a large string in an
 'image_blob' field.
 However when I retrieve this image it is displayed as a string, rather than
 as an image.

 Is there something else I need to do here to render the blob correctly as a
 jpeg file - possibly some sort of special template tag or blob handler.

 Note: This is about in small (1mb) record/entity blobs.  I'm *not* using
 the google blobstore here - just in case there is any confusion.

 Any working examples would be helpful here.

 TIA,
 BrendanC


[web2py] Re: GAE - Rendering uploaded Blob as jpeg image rather than as a string?

2012-02-23 Thread BrendanC
I thought the content type settings were handled automatically by the 
framework.
Anyway - for some reason setting the response.headers to 'image/jpeg' does 
not work - just get an empty/blank page. 
I must be  missing something else re handling gae blob properties - here's 
my test code:

Any further suggestions? 

Model:
# Image table - includes ref to image blob + lat/long for location/google 
map
db.define_table(
'xim',
Field('title', unique=True), 
Field('image','upload'),
Field('image_url'),

Field('modified_on','datetime',default=request.now,writable=False,readable=False)
)

Controller:
def list_images():

# Display Image as jpeg file - need to set HTTP Content type = 
image/jpeg in view
images=db(db.xim.id0).select(orderby=db.xim.title)
response.headers['Content-Type']='image/jpeg' 

return dict(images=images)

View:
  {{extend 'layout.html'}}
  
  h3Display Jpeg Images/h3
  
  table border=1
tr
   thImage Title/th
   thImage Blob/th 
/tr
{{for img in images:}}
tr
td{{ =img.title }}/td
td{{=img.image_blob }}//td 
/tr
{{pass}}
  /table



[web2py] Re: GAE - Rendering uploaded Blob as jpeg image rather than as a string?

2012-02-23 Thread BrendanC
OK - Quick follow up here - I was able to display an blob image using the 
call:

def list_image():

   myid = 1# test
image=db(db.xim.id==myid).select(orderby=db.xim.title)
response.headers['Content-Type']='image/jpeg' 

mystream = image.image_blob
return mystream

However this renders an image in separate page with no additional info. 
What I really want is to display the stream as part of a template (within 
 a table) with additional related image info (Title, Comments etc). IOW I 
want to embed the stream within an html template, rather than as a 
separate, standalone file.

Am I missing piece of the puzzle here?