I am working on a website with a MySQL backend. The site allows
users to upload files, such as jpg, gif, etc. I'm having issues
loading images from the database and getting them to display in the
webbrowser.
Since the raw image encoding contains characters MySQL doesn't like
when doing an INSERT, I encoded the image using Base64.encode64().
So, when I pulled the data back out, I do a Base64.decode64().
I also do a:
print cgi.header( "type=>image/jpg" ) so I have the correct header,
and then I dump the data by simply using <%= data %> as the only
information that is sent to the browser other than print cgi.header.
However, when I load the image, I get browser errors. In Firefox, it
knows it is image/jpg, but I get "The image (image path) cannot be
displayed, because it contains errors." And IE6 completely barfs,
asking to save the file because it doesn't know what type it is (and
saving the file as a jpg and then opening that up does not work)
What am I doing wrong? Does encoding/decoding in Base64 totally screw
this up? Any other recommended approaches? As I mentioned, Firefox is
aware of the fact it is image/jpg, but IE does not. In either case,
the raw data is not a properly encoded jpeg.