Re: Newbie Question: How to upload an image file and show it?

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Re: Newbie Question: How to upload an image file and show it?

Stephan Semerad
the upload function you got

now you need

-  to save the img name somewhere, 
- add a static directory (where you saved the image)
- write a function which renders the img in html with an     <img src="image.jpg" alt="">

its simple really. 

it fairly simple until you add javascript. to upload multiple images at once and need to verify the file extension and compress the images. 

On Friday, August 11, 2006 at 11:11:48 AM UTC+2, ye wrote:
I want to let the user upload an image file ,then display the image to
How can I do it?

I know how to upload file by reading the code in the
class FileDemo(object):

    def index(self):
        return """
            <form action="upload" method="post"
            filename: <input type="file" name="myFile" /><br />
            <input type="submit" />
            <a href="download"> downlaod </a>
        """ = True

    def upload(self, myFile):
        out = """<html>
            myFile length: %s<br />
            myFile filename: %s<br />
            myFile mime-type: %s <br />

        size = 0
        while True:
            data =
            if not data:
            size += len(data)
         return out % (size, myFile.filename, myFile.type) = True

And what should I do next to show the image ?

Is there any example about this?

You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at
For more options, visit