CGI Proplem displaying image

Waldemar Osuch osuchw at ecn.ab.ca
Sat May 8 18:54:32 EDT 2004


matthiasjanes at gmx.net (matthiasjanes) wrote in message news:<d588131f.0405071937.94e4f17 at posting.google.com>...
> Hi,
> Maybe someone of you can help me.
> 
> I'm trying to display an image in memory(open file) with an cgi script
> - but it want work proberly:
> 
> I'm running an Cgi webserver (CgiServerGui.py).
> 
> both files are in the /cgi/ folder
> 
> #################
> #my CGISRIPT: test.py
> 
> #! /usr/bin/env python
> 
> print ("Content-type: image/jpeg");
> print # End of headers!
> 
> filename="cgi-bin//dog.jpg"
> infile = open(filename, 'rb')
> doginmemory=infile.read()
> print doginmemory
> 
> ##################
>

Use sys.stdout for output in CGI scripts.
Escpecially with binary files.
Try this and see if the problem goes away

#################
#my CGISRIPT: test.py

#! /usr/bin/env python

import sys
sys.stdout("Content-type: image/jpeg\n\n")
 
filename="cgi-bin/dog.jpg"
img = open(filename, 'rb').read()
sys.stdout.write(img)

##################

Remember Google is your friend
http://starship.python.net/crew/davem/cgifaq/faqw.cgi

waldek



More information about the Python-list mailing list