URLRequest defaults to GET.
try adding
urlRequest.method = URLRequestMethod.POST

On Tue, Jan 13, 2009 at 8:18 AM, Ben Corneau <[email protected]> wrote:
> Here's a working example.
> Flex:
> ------------------------------------------------------
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";>
>
>     <mx:Button label="Upload File..." click="uploadFile()"/>
>
>     <mx:Script>
>         <![CDATA[
>
>             import flash.events.*;
>             import flash.net.*;
>             import mx.controls.Alert;
>
>             private var uploadURL:String =
> "http://www.server.com/upload.py/upload";;
>             private var urlRequest:URLRequest = new URLRequest(uploadURL);
>
>             private var fileUpload:FileReference = new FileReference;
>
>             private function uploadFile():void
>             {
>                 fileUpload.addEventListener(Event.SELECT, onFileSelected);
>                 fileUpload.addEventListener(Event.COMPLETE,
> onUploadComplete);
>                 fileUpload.browse();
>             }
>
>             private function onFileSelected(evt:Event):void
>             {
>                 fileUpload.upload(urlRequest);
>             }
>
>             private function onUploadComplete(evt:Event):void
>             {
>                 Alert.show("upload complete");
>             }
>         ]]>
>     </mx:Script>
>
> </mx:Application>
> ------------------------------------------------------
>
>
> web.py:
> ------------------------------------------------------
> #!/usr/local/bin/python-web
> import web
> urls = ('/upload', 'Upload')
> app = web.application(urls, globals())
> class Upload:
>     def POST(self):
>         input = web.input(Filedata={})
>         file = open("uploaded_files/" + input["Filedata"].filename, "w")
>         file.write(input["Filedata"].file.read())
>
> if __name__ == "__main__":
>     app.run()
> --------------------------------------------------
> HTH,
> Ben
> 2009/1/13 hhsuper <[email protected]>
>>
>> yes it's adobe's flex, but my side side(web.py) with html upload is ok,
>> and the client code(flex) work with django (and other server side) is ok,
>> that confused me, do you mind provider me a simple worked sample?
>>
>> 2009/1/13 Ben Corneau <[email protected]>
>>>
>>> I don't know what to make of your error, but I do have file upload using
>>> flex working. I'm assuming by flex you mean Adobe Flex.
>>>
>>> The following web.py code works for me.
>>>
>>> urls = ('/upload', 'Upload')
>>>
>>> class Upload:
>>>     def POST(self):
>>>
>>>         input = web.input(Filedata={})
>>>         file = open("images/" + input["Filedata"].filename, "w")
>>>         file.write(input["Filedata"].file.read())
>>>
>>> -Ben
>>>
>>> hhsuper wrote:
>>>
>>> i have a simple test, web.py impelement the file upload func, and tested
>>> with the html page ok, but when i upload the file with
>>>  flex (in the same site, actual in the same html page ), there is some
>>> error, follow
>>>
>>> beside, the same flex code used for django app is ok(i have a simple
>>> test)
>>>
>>> Traceback (most recent call last):
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\application.py",
>>>  line 211, in process
>>>     return self.handle()
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\application.py",
>>>  line 201, in handle
>>>     return self._delegate(fn, self.fvars, args)
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\application.py",
>>>  line 385, in _delegate
>>>     return handle_class(cls)
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\application.py",
>>>  line 360, in handle_class
>>>     return tocall(*args)
>>>   File "D:\Projects\truman2\app\controllers\scene.py", line 159, in POST
>>>     i = web.input(photo = {})
>>>   File
>>> "C:\Python25\lib\site-packages\web.py-0.31-py2.5.egg\web\webapi.py", line
>>>  208, in input
>>>     a = cgi.FieldStorage(fp=fp, environ=e, keep_blank_values=1)
>>>   File "C:\Python25\lib\cgi.py", line 534, in __init__
>>>     self.read_multi(environ, keep_blank_values, strict_parsing)
>>>   File "C:\Python25\lib\cgi.py", line 659, in read_multi
>>>     environ, keep_blank_values, strict_parsing)
>>>   File "C:\Python25\lib\cgi.py", line 536, in __init__
>>>     self.read_single()
>>>   File "C:\Python25\lib\cgi.py", line 669, in read_single
>>>     self.read_lines()
>>>   File "C:\Python25\lib\cgi.py", line 691, in read_lines
>>>     self.read_lines_to_outerboundary()
>>>   File "C:\Python25\lib\cgi.py", line 719, in read_lines_to_outerboundary
>>>     line = self.fp.readline(1<<16)
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\wsgiserver\__ini
>>> t__.py", line 206, in readline
>>>     data = self.rfile.readline(size)
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\wsgiserver\__ini
>>> t__.py", line 1024, in readline
>>>     data = self.recv(self._rbufsize)
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\wsgiserver\__ini
>>> t__.py", line 925, in recv
>>>     return self._sock.recv(size)
>>> timeout: timed out
>>>
>>> Traceback (most recent call last):
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\application.py",
>>>  line 209, in process
>>>     return p(lambda: process(processors))
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\application.py",
>>>  line 552, in processor
>>>     return handler()
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\application.py",
>>>  line 209, in <lambda>
>>>     return p(lambda: process(processors))
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\application.py",
>>>  line 216, in process
>>>     raise self.internalerror()
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\application.py",
>>>  line 449, in internalerror
>>>     return debugerror.debugerror()
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\debugerror.py",
>>> line 299, in debugerror
>>>     return web._InternalError(djangoerror())
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\debugerror.py",
>>> line 289, in djangoerror
>>>     return t(exception_type, exception_value, frames)
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\template.py", li
>>> ne 850, in __call__
>>>     return BaseTemplate.__call__(self, *a, **kw)
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\template.py", li
>>> ne 768, in __call__
>>>     return self._join_output(out)
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\template.py", li
>>> ne 774, in _join_output
>>>     for name, value in out:
>>>   File
>>> "C:\Python25\lib\site-packages\web.py-0.31-py2.5.egg\web\debugerror.pyc",
>>>  line 183, in __template__
>>>     $if ctx.output or ctx.headers:
>>>   File
>>> "C:\Python25\lib\site-packages\web.py-0.31-py2.5.egg\web\webapi.py", line
>>>  208, in input
>>>     a = cgi.FieldStorage(fp=fp, environ=e, keep_blank_values=1)
>>>   File "C:\Python25\lib\cgi.py", line 534, in __init__
>>>     self.read_multi(environ, keep_blank_values, strict_parsing)
>>>   File "C:\Python25\lib\cgi.py", line 654, in read_multi
>>>     environ, keep_blank_values, strict_parsing)
>>>   File "C:\Python25\lib\cgi.py", line 536, in __init__
>>>     self.read_single()
>>>   File "C:\Python25\lib\cgi.py", line 669, in read_single
>>>     self.read_lines()
>>>   File "C:\Python25\lib\cgi.py", line 691, in read_lines
>>>     self.read_lines_to_outerboundary()
>>>   File "C:\Python25\lib\cgi.py", line 719, in read_lines_to_outerboundary
>>>     line = self.fp.readline(1<<16)
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\wsgiserver\__ini
>>> t__.py", line 206, in readline
>>>     data = self.rfile.readline(size)
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\wsgiserver\__ini
>>> t__.py", line 1024, in readline
>>>     data = self.recv(self._rbufsize)
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\wsgiserver\__ini
>>> t__.py", line 925, in recv
>>>     return self._sock.recv(size)
>>> timeout: timed out
>>>
>>> Traceback (most recent call last):
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\application.py",
>>>  line 209, in process
>>>     return p(lambda: process(processors))
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\application.py",
>>>  line 537, in processor
>>>     return handler()
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\application.py",
>>>  line 209, in <lambda>
>>>     return p(lambda: process(processors))
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\application.py",
>>>  line 216, in process
>>>     raise self.internalerror()
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\application.py",
>>>  line 449, in internalerror
>>>     return debugerror.debugerror()
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\debugerror.py",
>>> line 299, in debugerror
>>>     return web._InternalError(djangoerror())
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\debugerror.py",
>>> line 258, in djangoerror
>>>     _get_lines_from_file(filename, lineno, 7)
>>>   File
>>> "c:\python25\lib\site-packages\web.py-0.31-py2.5.egg\web\debugerror.py",
>>> line 243, in _get_lines_from_file
>>>     context_line = source[lineno].strip('\n')
>>> IndexError: list index out of range
>>>
>>> --
>>> Su zhaohui   苏召辉
>>>
>>>
>>>
>>>
>>
>>
>>
>> --
>> Yours sincerely
>>
>> Jack Su
>>
>>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to