[Twisted-Python] How would I upload/download files through twisted.web

Mario Ruggier mario at ruggier.org
Fri May 9 17:37:09 MDT 2003


Not sure what you mean, but file upload may be done like so:

## fileup.rpy

import twisted.web.resource

class FileUpResource(twisted.web.resource.Resource):

     isLeaf = 1

     def render(self, request):
         request.setHeader('Content-Type', 'text/html; charset=utf-8')
         args = request.args
         pageTitle = 'file upload test'

         return (u"""
<html>
   <head>
     <title>%(pageTitle)s</title>
     <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
   </head>
   <body>
     <h1>%(pageTitle)s</h1>
     <form method="post" enctype="multipart/form-data">
     <table>
     <tr><td> file: </td><td> <input name='file' type='file'> </td></tr>
     </table>
     <input type=submit>
     </form>
     <hr/>
     <p>Form args:<br/>%(args)s</p>
     <hr/>
     </body>
</html>""" % vars()).encode()

resource = FileUpResource()

##


On jeudi, mai 8, 2003, at 23:38 Europe/Amsterdam, John D. Heintz wrote:

> Any help of this issue? I've got a good feeling about twisted but:
>
> a) don't have time to explore http and twisted
> b) don't yet completely grok the asyncronous flow
>
> If I can get an http upload/downloader working I can you Twisted on a
> project for a customer to get a  better performing web server than the
> BaseHTTPServer from python.
>
> Thanks for your time,
> John
>
> On Mon, 2003-05-05 at 13:29, John D. Heintz wrote:
>> Hi all,
>>
>> I tried searching the mailing list and google but ended up more
>> confused. Sorry if this is in the docs and I missed it, just redirect
>> me.
>>
>> Question: How do I write a simple twisted.web server to receive an
>> uploaded file, process it, and return a different file for
>> download/launch.
>>
>> The last part does have some examples, but I include it hear for
>> completeness.
>>
>> My intuition tells me that this kind of thing is "trivial" in twisted,
>> but I'm having a hard time unraveling the knot. I started working on a
>> custom Resource but only got so far.
>>
>> Can someone post a small python script (like web.py in examples) that
>> does this?
>>
>> Thanks for the time,
>> John
>>
>> -- 
>> John D. Heintz | Senior Developer
>>
>> 1016 La Posada Dr. | Suite 240 | Austin TX 78752
>> T 512.380.0347 | jheintz at isogen.com
>>
>> http://www.isogen.com
> -- 
> John D. Heintz | Senior Developer
>
> 1016 La Posada Dr. | Suite 240 | Austin TX 78752
> T 512.380.0347 | jheintz at isogen.com
>
> http://www.isogen.com
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
Best regards,

	Mario Ruggier

email      mario at ruggier.org
home      +33 4 50 41 96 14
mobile    +41 79 214 0791





More information about the Twisted-Python mailing list