Hi all, hope someone has a suggestion on how to handle this issue,
which I am running out of optiohns on how to deal with it.
In MySQL, i have a table with a "text" (LONGTEXT) column that I use to
store base64-encoded image information, I do low-level validation to
make sure the data is actually an image, and the size and image
properties (height, width) are always checked, in short, I only store
data for very small images (avatars, in this case). I am positive that
the base64-encoded data corresponds to that of a valid image if I
base64-decode it.
Since I store the raw data, I am also storing its content type in
another column in the same table.
Now, here is the problem:
Here's my view:
<img src="{{=apphelper.display_image(username=username)}}" alt="" />
And my "apphelper" defined as a module and loaded up in one of my
controllers has this:
def display_image(self, auth_user):
""" Returns the avatar raw data """
avatar_info = self.db
(self.db.zf_member_avatars.auth_user==auth_user).select
(self.db.zf_member_avatars.content_type,
self.db.zf_member_avatars.avatar_image)
if len(avatar_info):
raw_image = base64.decodestring(avatar_info
[0].avatar_image)
self.response.headers['Content-Type'] = '%s' % (avatar_info
[0].content_type)
return raw_image
Problem is that invariably I see the message "The Image "..." cannot
be displayed because it contains errors.
I am leaning towards this being some kind of encoding or something, if
I view the contents of "raw_image" before is passed back to the view,
the "raw" data is a correct, binary representation of my original file
that I uploaded and encoded previously.
Thanks for any pointers..
Julio
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---