You can use the idea of the fileUpload tool and then in the same tool
add to the cherrypy.session the temporary file and external id (which
can be created with javscript and should be unique from the client side)
and the size of the request:
e.g.
POST /filemgm/_upload?fid=1234ab
def bigfile(self, fid, **kwargs):
...
...
cherrypy.session[fid] = \
(TEMPORARY_FILEPATH,
cherrypy.request.headers['Content-length'])
cherrypy.session.save()
...
...
Then periodically interrogate the server asking for the file
GET /filemgm/_status?fid=1234ab
the filemgm._status method adds the logics to return the upload
percentage which you can know from the session, the fid parameter and
the percentage from the relation of the header 'Content-length' and the
current size of the file.
e.g.
import os
def _status(self, fid):
try:
tempfilepath, length = cherrypy.session[fname]
except (TypeError, ValueError): # is None or unpack error
return 'done'
else:
currsize = os.stat(tempfilepath).st_size
return float(currsize) / length * 100 # float is just for python2
For this to work you need to have some client-side code to keep updating
the percentage to the user, you can easily make and async post with
jquery to post the first request and then ask for the status of the fid.
The fundamental problem is that you cannot respond to the client
when the uploading of the request (the file) is being done, so I think
that the solution should be in the form of a secondary request.
The essence from the idea that I propose is
1.- Had an external id of the file that you are uploading.
2.- Make a secondary request to check the status of the id that the
first request make, which can be one with an streamed response
or many with precise responses.
Also I'm overlooking that when the request is getting processed in the
first request the file that has being created gets periodically flushed
to have a trustworthy uploading percentage.
I hope that help you to consider this as an alternative.
Cheers.
> --
> You received this message because you are subscribed to the Google
> Groups "cherrypy-users" group.
> To post to this group, send email to
cherryp...@googlegroups.com.
> To unsubscribe from this group, send email to cherrypy-users
> +
unsub...@googlegroups.com.
> For more options, visit this group at
>
http://groups.google.com/group/cherrypy-users?hl=en.
--
Rivera²