Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Ticket #216 (defect)

Opened 4 years ago

Last modified 4 years ago

With enctype="multipart/form-data"; all your handler arguments are instances of cgi.FieldStorage.

Status: closed (fixed)

Reported by: xerophyte Assigned to: rdelon
Priority: normal Milestone: 2.1
Component: CherryPy code Keywords: cgi fileupload
Cc:

When you use multipart/form-data on the form, cherrypy pass the all your handler arguments as cgi.fieldStorage.

code:

class FileUploadDemo(object):

4 myfile=None 5 def index(self): 6 return """ 7 <html><body> 8 <form action="upload" method="post" enctype="multipart/form-data"> 9 <input type="hidden" name="id" value="testid" /> 10 filename: <input type="file" name="myFile" /><br /> 11 <input type="submit" /> 12 </form> 13 </body></html> 14 """ 15 index.exposed = True 16 17 def upload(self,id, myFile): 18 19 if myFile.file is not None: 20 self.myfile = myFile.file.readlines() 21 else: 22 self.myfile = "could not fild the file" 23 return """ 24 <html><body> 25 myFile length: %s<br /> 26 myFile filename: %s<br /> 27 id value :%s <br /> 28 myFile mime-type: %s <br /> 29 file content : <pre>%s</pre> 30 </body></html> 31 """ % (len(myFile.value), 32 myFile.filename,id.value, 33 myFile.type,myFile.file.read()) 34 upload.exposed = True 35 36 @cherrypy.expose 37 def view(self): 38 if self.myfile is None: 39 return 40 else: 41 return """ 42 <html><body> 43 file content : <pre>%s</pre>""" %self.myfile 44 45 cherrypy.root = FileUploadDemo() 46 47 if name == 'main': 48 # Use the configuration file tutorial.conf. 49 cherrypy.config.update(file = 'tutorial.conf') 50 # Start the CherryPy server.

I assume, it should be bug, either way wanna open a ticket.

Change History

07/06/05 11:44:51: Modified by anonymous

code again :

class FileUploadDemo(object):
    myfile=None
    def index(self):
        return """
        <html><body>
            <form action="upload" method="post" enctype="multipart/form-data">
            <input type="hidden" name="id" value="testid" />
            filename: <input type="file" name="myFile" /><br />
            <input type="submit" />
            </form>
        </body></html>
        """
    index.exposed = True

    def upload(self,id, myFile):

        if myFile.file is  not None:
            self.myfile = myFile.file.readlines()
        else:
            self.myfile = "could not fild the file"
        return """
        <html><body>
            myFile length: %s<br />
            myFile filename: %s<br />
            id value :%s <br />
            myFile mime-type: %s <br />
            file content : <pre>%s</pre>
        </body></html>
        """ % (len(myFile.value),
               myFile.filename,id.value,
               myFile.type,myFile.file.read())
    upload.exposed = True

    @cherrypy.expose
    def view(self):
        if self.myfile is None:
            return ''
        else:
            return """
            <html><body>
            file content : <pre>%s</pre>""" %self.myfile

cherrypy.root = FileUploadDemo()

if __name__ == '__main__':
    # Use the configuration file tutorial.conf.
    cherrypy.config.update(file = 'tutorial.conf')
    # Start the CherryPy server.
    cherrypy.server.start()

07/07/05 04:45:20: Modified by rdelon

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in changeset [422]. Thanks for reporting the bug.

Hosted by WebFaction

Log in as guest/cpguest to create tickets