My favorites | Sign in
Project Logo
                
Search
for
Updated Mar 11, 2009 by zatepyakin
Labels: Featured
MultipartURLLoader  
Custom URLLoader class (not socket) to send multipart form data.

Multipart URLLoader Class

During one of the projects I faced a problem to upload multipart/form-data to server using Flash. I need to do it using Actionscript only. The idea was to send to server an image generated in flash and several variables but all this data had to be POST. I found several projects that were using Flash Socket to send multipart requests to server but the problem was that sockets required custom server configuration to work. As you understand we cant ask remote service to reconfigure their system only because we need it. So the only way was to build your own custom URLLoader class (not socket) to send multipart form data. Unfortunately there is a problem getting progress event. We cant show any progress during sending data to server because flash doesn't support it. (the same problem with sockets)

How To

Complete source code and test usage example with small PHP script available in my repository

Change Log


Comment by quentin.t, Mar 06, 2009

Really good class! I've simply added a getter for the _loader private var to add custom event listeners... I think you should add that too!

Comment by zatepyakin, Mar 11, 2009

@quentin.t Thanx for comment I've updated class with more features and made it more customizable. Also I've added getter for URLLoader instance.

Comment by meonimarco, Apr 02, 2009

Good! I've used it with satisfaction!! The best multipart loader i've found!

Comment by dchelimsky, May 11, 2009

Hello - I'm kinda new to actionscript, so bear with me. I'm using a modified version of the example you've provided on http://blog.inspirit.ru/?p=139 - my code is here: http://gist.github.com/110266. The post URL has been removed, but that example is otherwise complete.

I can post a bitmap file (i.e. somefile.bmp) to that URL with an HTML multipart form and it receives the post and successfully converts the uploaded bitmap image to a jpeg. When I try to upload from flash, however, I get "Improper image header `foo.bmp' @ bmp.c/ReadBMPImage/593".

Any ideas about this or pointers to docs would be most appreciated.

Comment by gbrad...@rocket.co.uk, Sep 21, 2009

Hi,

I'm having a problem which may or may not be caused by URLLoader that is wrapped by your multipart loader. Basically, everything works fine when I test my movie from within Flash - the request is made and files are uploaded. However, whenever I try from a browser, the request simply doesn't start. No IO / security / argument exceptions, no event listeners firing, not even Event.OPEN for the URLLoader.

At first I thought its some kind of security error, but the request works fine if I omit the call to addFile(). Besides, there's simply no indication of anything going wrong - its as if the movie just hangs.

I stripped back all my other code, and tried just passing an empty ByteArray? to the first argument of addFile(), but that makes no difference.

I'm thinking that this is problem with URLLoader rather than your code, but have you come across anything like this before?

Comment by gbrad...@rocket.co.uk, Sep 22, 2009

My problem described above has been solved, I've filed an issue regarding it.

Comment by signalfive.demo, Oct 13, 2009

How do I catch a response header?


Sign in to add a comment
Hosted by Google Code