List Info

Thread: File upload and streams in 2.2




File upload and streams in 2.2
user name
2006-04-13 11:37:41

I'm attempting to implement the monitoring of file uploads
in CheeryPy
2.2 (used from TurboGears).  This is for the ubiquitous
progress bar
which is vital for user feedback when uploading large files.

The easiest point of entry I've found is overriding the
'make_file'
method in _cpcgifs.FieldStorage so that it creates a file
with a custom
naming that I can track.  The client sends asynchronous
requests and
the server returns the size of the temporary file.

Should be straight forward and I can hack _cpcgifs.py to put
the
'make_file' in but ideally it'd be better if CherryPy
supported this.

Looking at the previous (2.1) solution for uploading files
gave me a
ray of hope.  It uses a filter and allows user code to
create
cgi.FieldStorage, exactly what I wanted! - a place to insert
my own
derived FieldStorage with it's custom 'make_file'.

Unfortunately I've been unable to get something similar
working in
CP2.2 - it looks like BaseInputFilter has dissapeared and
there is no
mention of 'afterRequestHeader' or rather
'after_request_header'
anywhere in the code.  So it looks like this path has been
closed.

Any idea how I can use my own FieldStorage implementation
without
hacking the original source code?

Cheers,

Justin


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at http://
groups.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

File upload and streams in 2.2
user name
2006-04-13 16:59:56

Additionally, after looking at the source code I came up
with this
solution:

from cherrypy import _cpcgifs

class MyFieldStorage(_cpcgifs.FieldStorage):
    def make_file(self, binary=None):
        print "Making binary file"

        filename = self.filename
        length =
int(cherrypy.request.headerMap['Content-Length'])

        print "file: %s  length:%d" % (filename,
length)

        dest_filename = "c:/tmp/uploads/" +
filename

        return open(dest_filename, "w+b");

_cpcgifs.FieldStorage = MyFieldStorage

So, to implement an upload progress bar you can use the
above to create
the file and make a record somewhere (session or database)
of the
filename (dest_filename) and size.

On the client side, make a periodic asynchronous call to the
server
requesting the total uploaded so far.  The server returns
the current
size of the uploading file (dest_filename).  A dash of DHTML
to show
your progress bar should do nicely.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at http://
groups.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )