Re: putting binary data into the response

2007-07-13 Thread Christoph Haas

On Fri, Jul 13, 2007 at 01:09:06PM -0700, Jose Galvez wrote:
 Hi all, I know this should be simple but I can't find the answer anywhere, I
 have some images in a database that I need to send to a webpage.  So I have a
 simple controller that should just send the binary data but I can't find how 
 to
 stuff binary data into the response object.  here is my code
 
def photo(self, id):
 sac = model.sac
 q = sac.query
 binaryImage = q(model.Students).get(id).photo
 res = Response()
 res.headers['Content-type'] = 'image/jpeg'
 res.write(binaryImage)
 return res
 
 which displays nothing

I have written a function that returns XML. It looks like:

response = pylons.Response(the_actual_xml_string)
response.headers['content-type'] = text/xml
return response

Would that help? I just didn't use .write() here.

 Christoph


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: putting binary data into the response

2007-07-13 Thread Jose Galvez
Nope just stuffed them into the database as blobs


On 7/13/07, voltron [EMAIL PROTECTED] wrote:


 hmm, did you first convert the image as base 64 before storage?

 On Jul 13, 10:09 pm, Jose Galvez [EMAIL PROTECTED] wrote:
  Hi all, I know this should be simple but I can't find the answer
 anywhere, I
  have some images in a database that I need to send to a webpage.  So I
 have
  a simple controller that should just send the binary data but I can't
 find
  how to stuff binary data into the response object.  here is my code
 
 def photo(self, id):
  sac = model.sac
  q = sac.query
  binaryImage = q(model.Students).get(id).photo
  res = Response()
  res.headers['Content-type'] = 'image/jpeg'
  res.write(binaryImage)
  return res
 
  which displays nothing
 
  Jose


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: putting binary data into the response

2007-07-13 Thread Jose Galvez
Didn't work, what I get if I look at the Response.content is [read-only
buffer for 0x016b00e0, size-1, offset 0, at 0x016b0340]

also if I try Response(binaryImage[0:]) the images gets truncated, because
its trying to interpret the image as a string
Jose

On 7/13/07, Christoph Haas [EMAIL PROTECTED] wrote:


 On Fri, Jul 13, 2007 at 01:09:06PM -0700, Jose Galvez wrote:
  Hi all, I know this should be simple but I can't find the answer
 anywhere, I
  have some images in a database that I need to send to a webpage.  So I
 have a
  simple controller that should just send the binary data but I can't find
 how to
  stuff binary data into the response object.  here is my code
 
 def photo(self, id):
  sac = model.sac
  q = sac.query
  binaryImage = q(model.Students).get(id).photo
  res = Response()
  res.headers['Content-type'] = 'image/jpeg'
  res.write(binaryImage)
  return res
 
  which displays nothing

 I have written a function that returns XML. It looks like:

 response = pylons.Response(the_actual_xml_string)
 response.headers['content-type'] = text/xml
 return response

 Would that help? I just didn't use .write() here.

 Christoph


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: putting binary data into the response

2007-07-13 Thread voltron

I think you have to encode it Jose

take a look at the return image function here

http://mail.python.org/pipermail/python-list/2004-May/261846.html



On Jul 13, 10:09 pm, Jose Galvez [EMAIL PROTECTED] wrote:
 Hi all, I know this should be simple but I can't find the answer anywhere, I
 have some images in a database that I need to send to a webpage.  So I have
 a simple controller that should just send the binary data but I can't find
 how to stuff binary data into the response object.  here is my code

def photo(self, id):
 sac = model.sac
 q = sac.query
 binaryImage = q(model.Students).get(id).photo
 res = Response()
 res.headers['Content-type'] = 'image/jpeg'
 res.write(binaryImage)
 return res

 which displays nothing

 Jose


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: putting binary data into the response

2007-07-13 Thread voltron

hmm, did you first convert the image as base 64 before storage?

On Jul 13, 10:09 pm, Jose Galvez [EMAIL PROTECTED] wrote:
 Hi all, I know this should be simple but I can't find the answer anywhere, I
 have some images in a database that I need to send to a webpage.  So I have
 a simple controller that should just send the binary data but I can't find
 how to stuff binary data into the response object.  here is my code

def photo(self, id):
 sac = model.sac
 q = sac.query
 binaryImage = q(model.Students).get(id).photo
 res = Response()
 res.headers['Content-type'] = 'image/jpeg'
 res.write(binaryImage)
 return res

 which displays nothing

 Jose


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---



Re: putting binary data into the response

2007-07-13 Thread Jose Galvez
Thanks everyone for the help in the end I had corrupt data in the database
so it was showing me exactly what it was supposed to.
Jose

On 7/13/07, Jose Galvez [EMAIL PROTECTED] wrote:

 Didn't work, what I get if I look at the Response.content is [read-only
 buffer for 0x016b00e0, size-1, offset 0, at 0x016b0340]

 also if I try Response(binaryImage[0:]) the images gets truncated, because
 its trying to interpret the image as a string
 Jose

 On 7/13/07, Christoph Haas [EMAIL PROTECTED] wrote:
 
 
  On Fri, Jul 13, 2007 at 01:09:06PM -0700, Jose Galvez wrote:
   Hi all, I know this should be simple but I can't find the answer
  anywhere, I
   have some images in a database that I need to send to a webpage.  So I
  have a
   simple controller that should just send the binary data but I can't
  find how to
   stuff binary data into the response object.  here is my code
  
  def photo(self, id):
   sac = model.sac
   q = sac.query
   binaryImage = q(model.Students).get(id).photo
   res = Response()
   res.headers['Content-type'] = 'image/jpeg'
   res.write(binaryImage)
   return res
  
   which displays nothing
 
  I have written a function that returns XML. It looks like:
 
  response = pylons.Response(the_actual_xml_string)
   response.headers['content-type'] = text/xml
  return response
 
  Would that help? I just didn't use .write() here.
 
  Christoph
 
 
   
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
pylons-discuss group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~--~~~~--~~--~--~---