[Twisted-web] nevow FileUpload

David Ferlier david at endlessremix.shacknet.nu
Wed Sep 8 10:17:02 MDT 2004


First, you should know that there is a very disturbing bug in
NevowSite's code that makes twisted block while nevow creates the
cgi.FieldStorage's instance in finish() (so your website won't be able
to answer requests while the file is uploaded, which makes it
useless). To correct that you need to overload NevowSite : just
overload its finish() method and remove the creation of the

That said, accessing file data from the FieldStorage instance is quite
easy. Let's say that you now have the request object. To access file
data from the 'myfile' field :

file = request["myfile"].file
filedata = file.read()

Hope it helps,


On Wed, Sep 08, 2004 at 12:01:02PM +0100, Williamson, Mark wrote:
> Hi, 
> I'm building a web app with nevow/twisted and I'm really 
> impressed. 
> I'm having a small problem with Formless though when trying to 
> upload a file: 
> here is my interface:
> class IAddDocument( formless.TypedInterface ):
>    """Interface for Add Document form"""
>    def addDocument( self , context = annotate.Context() , fdata =
> annotate.FileUpload( required = True ) ):
>       pass
>    addDocument = formless.autocallable( addDocument )
> The form renders fine (I'm using a template pretty much based on the one in
> one of the 
> tutorials except I've messed about with the table layout a bit) and lets me
> choose a file
> for upload - it also seems to upload the file. However when my method is
> called 
> on my page class: 
>    def addDocument( self , context , fdata ):
>        ...
> fdata is None. I've looked at the request from the context and the filename
> seems to be there 
> but not the file data. 
> Can anyone shed any light on this. Its a bit of a sticking point for me 
> right now
> cheers 
> mark 
> **************************************************************************
> Experience the British Library online at www.bl.uk 
> Help the British Library conserve the world's knowledge. Adopt a Book.
> www.bl.uk/adoptabook 
> *************************************************************************
> The information contained in this e-mail is confidential and may be legally
> privileged. It is intended for the addressee(s) only. If you are not the
> intended recipient, please delete this e-mail and notify the
> postmaster at bl.uk : The contents of this e-mail must not be disclosed or
> copied without the sender's consent. 
> The statements and opinions expressed in this message are those of the
> author and do not necessarily reflect those of the British Library. The
> British Library does not take any responsibility for the views of the
> author. 
> ************************************************************************* 
> _______________________________________________
> Twisted-web mailing list
> Twisted-web at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

	David Ferlier -- david at endlessremix.shacknet.nu

More information about the Twisted-web mailing list