Uploading big files wit cherrypy

Farsheed Ashouri rodmena.com at gmail.com
Tue Feb 10 10:38:37 EST 2009


I use this code to upload using cherrypy:
#========Code Start==========
class NoteServer(object):
    _cp_config = { 'tools.sessions.on': True }

    def index(self):
        return """
        <html><body>
            <form action="upload" method="post" enctype="multipart/
form-data">
            filename: <input type="file" name="myFile" /><br />
            <input type="submit" />
            </form>
            <p>
            Pars Studios, 2009
            </p>
        </body></html>
        """
        #~ return compose().run()
    index.exposed = True
    def upload(self, myFile):
        out = """<html>
        <body>
            myFile length: %s<br />
            myFile filename: %s<br />
            myFile mime-type: %s
        </body>
        </html>"""

        # Although this just counts the file length, it demonstrates
        # how to read large files in chunks instead of all at once.
        # CherryPy uses Python's cgi module to read the uploaded file
        # into a temporary file; myFile.file.read reads from that.
        size = 0
        allData=''
        while True:
            data = myFile.file.read(8192)
            allData+=data
            if not data:
                break
            size += len(data)
        savedFile=open(myFile.filename, 'wb')
        savedFile.write(allData)
        savedFile.close()
        return out % (size, myFile.filename, myFile.type)
        #~ return allData
    upload.exposed = True
#========Code End============

But I couldn't upload files bigger than 100Mb.
Why and what is workaround?

Thanks in advanced.



More information about the Python-list mailing list