Trying to upload file through flex

22 views
Skip to first unread message

Adi

unread,
Oct 20, 2009, 3:05:41 AM10/20/09
to web2py-users
Hi,

I'm developing an application that uses web2py for server and air+flex
for user interface. Also, I'm a newbie.
The query is related to this post: http://groups.google.com/group/web2py/msg/b1c6d74aead0a401

I'm trying to upload a video file through Flex. Now Flex will send the
request in this format:

Content-Type: multipart/form-data; boundary=AaB03x
--AaB03x
Content-Disposition: form-data; name="Filedata";
filename="example.flv"
Content-Type: application/octet-stream
... contents of example.flv ...
--AaB03x--

I tried to use this code for upload:

def upload():
"""
uploads an flv file to server, creates a database entry for it.
"""
# reference: http://bit.ly/remoteupload
return SQLFORM(db.videodata, fields=['flvcopy']).accepts
(request.vars, formname=None)

where "flvcopy" is the file upload field. However, this is creating a
new record with all fields as "None" and "flvcopy" having nothing (not
even None).

How do I match my server code to upload the given request?

Adi

unread,
Oct 20, 2009, 12:13:46 PM10/20/09
to web2py-users
Any help on this?

On Oct 20, 12:05 pm, Adi <aditya.sa...@gmail.com> wrote:
> Hi,
>
> I'm developing an application that uses web2py for server and air+flex
> for user interface. Also, I'm a newbie.
> The query is related to this post:http://groups.google.com/group/web2py/msg/b1c6d74aead0a401
>
> I'm trying to upload a video file throughFlex. NowFlexwill send the

mdipierro

unread,
Oct 20, 2009, 1:14:41 PM10/20/09
to web2py-users
Sorry, I am not familiar with flash but this is wrong anyway:

return SQLFORM(db.videodata, fields=['flvcopy']).accepts(request.vars,
formname=None)

because it should return the form. It would only return True/False
from accept

I do not think flex is submitting to a form. I think you may need to
do something like

db.table.insert(field=db.table.field.store(request.body,'filename'))

Massimo

Adi

unread,
Oct 21, 2009, 2:45:18 AM10/21/09
to web2py-users
Tried this once - it stores entire request as text. Trying to figure
out a way.

Adi

unread,
Oct 21, 2009, 3:13:55 AM10/21/09
to web2py-users
Here's an update:

The POST request when seen as text looks like this:

------------cH2Ij5cH2ae0gL6Ef1ae0cH2KM7ae0
Content-Disposition: form-data; name="Filename"

test video.flv
------------cH2Ij5cH2ae0gL6Ef1ae0cH2KM7ae0
Content-Disposition: form-data; name="Filedata"; filename="test
video.flv"
Content-Type: application/octet-stream

...video content here in junk chars...
------------cH2Ij5cH2ae0gL6Ef1ae0cH2KM7ae0
Content-Disposition: form-data; name="Upload"

Submit Query
------------cH2Ij5cH2ae0gL6Ef1ae0cH2KM7ae0--

It looks like a form submit. My web2py code is this:

def upload():
"""
uploads an flv file to server, creates a database entry for it.
"""
db.videodata.insert(flvcopy=db.videodata.flvcopy.store
(request.vars.Filedata,'test1.flv'))

but this gives me an error I cannot understand.

Traceback (most recent call last):
File "gluon/restricted.py", line 184, in restricted
File "C:/Home/Software/Development/web2py/applications/videotag/
controllers/default.py", line 72, in <module>
File "gluon/globals.py", line 102, in <lambda>
File "C:/Home/Software/Development/web2py/applications/videotag/
controllers/default.py", line 70, in upload
File "gluon/sql.py", line 2357, in store
File "shutil.pyc", line 21, in copyfileobj
File "cgi.pyc", line 548, in __getattr__
AttributeError: read

Any help here?

mdipierro

unread,
Oct 21, 2009, 9:26:24 AM10/21/09
to web2py-users
Try

db.videodata.insert(flvcopy=db.videodata.flvcopy.store
(request.vars.Filedata.file,'test1.flv'))

Adi

unread,
Oct 31, 2009, 2:11:02 AM10/31/09
to web2py-users
It works! Thanks.
Reply all
Reply to author
Forward
0 new messages