12.15.2006

Flex upload component

Wow, can't believe its almost Christmas, been busy with alot of projects that I almost forgot me and Cahlan have a blog, guess time flies when you stare at code all day.

I did manage to find some time to put the file upload example into a Flex component. I was going to tweek this some more until I felt it was ready for use, but that was weeks ago. So here it is, if anyone wants to change/improve it, be my guest. And as always, right-click to download source.

80 Comments:

At 12/15/06 7:56 PM, Anonymous Anonymous said...

Great!

 
At 12/16/06 4:56 AM, Anonymous Maarten said...

Thanx a lot for sharing this!!!

I was searching yesterday for an example like this and when I was reading my blog list this morning it was just in front of me :D

 
At 12/18/06 12:07 PM, Anonymous Anonymous said...

that's great,but no source code

 
At 12/18/06 2:28 PM, Blogger Cahlan said...

Are you using Firefox? If so, try clearing your cache and restarting Firefox. We found a weird bug where somehow the Flash 9 player was going to random bookmarks when trying to view items in the context menu.

 
At 12/23/06 11:08 PM, Anonymous Anonymous said...

function return_result return xml,
how can i get it by component and show it?

 
At 12/30/06 12:35 AM, Anonymous Chris Seahorn said...

You can always count on the Cowboys for quality content. Great example guys!

 
At 1/22/07 4:26 PM, Blogger KaOs said...

Thanks for the component!!!! Its great!!!

To read the result XML you should add something like this at startUpload function:

_refUploadFile.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, onUploadCompleteData);

and create a new function called onUploadCompleteData.

 
At 1/27/07 2:51 PM, Blogger johann said...

Great example !

Is Flex Data Service mandatory for using this? (since the project seems to require Flex JSP taglibs that are only available with FDS)

Would it be complicated to port it to PHP or simpler JSP without Flex TagLibs?

Thanks in advance!

 
At 4/12/07 8:42 PM, Blogger D!gOW's said...

Hi, unhappyly, in my Online server, I am getting this error:

Error #2044: uploadIoError Unhandled:. text=Error #2038: File I/O Error. URL: http://digows.orgfree.com/FlexUp/upload.php

You have idea of because this is occurring?

My Other URL:
http://www.calcadosrosa.com.br/a/
http://digows.orgfree.com/FlexUp/

Thanks!!

my Email:rpffoz @ hotmail.com

From:
------------------------------
| Rodrigo Pereira Fraga|
http://e-digows.blogspot.com

e-mails: rpffoz@hotmail.com
rfraga@itaipu.gov.br
------------------------------

 
At 4/23/07 11:02 PM, Anonymous Jack Daniel said...

I was able to implement your component very nicely into one of my sites. I'm using it for image uploading. The problem I'm running into is timeouts (I think).

At work with a fast broadband connection, I can upload several files that are 1MB each with no problems whatsoever (PHP backend). At home, on a DSL connection, I'm able to upload a 50KB file easily, but anything just a bit bigger, say 200KB, and I get an IOError. Is there any way to remedy this problem in the application itself, either flex or php, as opposed to server-side configuration?

 
At 4/24/07 12:00 PM, Anonymous Anonymous said...

Jack Daniel:

I've run into this problem with my file uploader in .net. However, it was easily remedied by changing the page timeout settings on the server. Also, depending on your web server, you may be able to change the timeout settings on your upload script file. Definitely don't start in flash or flex looking for solutions, it will only waste your time.

 
At 4/24/07 7:54 PM, Anonymous Jack Daniel said...

ehh...i was hoping there was just some property i was overlooking either in my mxml or php. my hosting provider offers me very little access to the server. maybe i'll brave the support lines one more time...

thanks.

 
At 4/26/07 9:51 PM, Anonymous Brian said...

Jack, the FileReference class officially has a limitation of 100 meg.

 
At 5/23/07 7:26 AM, Anonymous JabbyPanda said...

Сurrently your upload demo is broken:


GET /crossdomain.xml HTTP/1.1
Host: weblog.cahlan.com

The requested URL /crossdomain.xml was not found on this server

 
At 6/11/07 7:26 PM, Anonymous Jarand said...

Hi, This look very great..
Im currently making my own CMS for my customers, and is making some of it in Flex.
I have come to a point where i want the image uploading for the gallery to be in Flex, and was wondering if i could use your FileUpload.mxml file?

Jarand

 
At 6/11/07 7:28 PM, Anonymous Jarand said...

Hi.
This look very great.
Im currently making my own CMS for my customers, and is looking for a file uploader for my gallery function.
I was wondering if i could use your fileManager.xml file?

Jarand

 
At 6/23/07 2:48 PM, Blogger fahrulazmi said...

i'm very sure that i've done everything correctly.

why am i getting an IOError???

do i have to tweak my server?

 
At 6/23/07 4:01 PM, Blogger Cahlan said...

You have to make sure you have read/write privileges on the the folder you are trying to complete the upload to.

 
At 6/24/07 11:32 AM, Blogger fahrulazmi said...

i've chmod the directory on my server to 777. but still get IOError...

i edited your code to make the app i'm creating for my college able to upload pictures. many thanks for the source code. :)

 
At 7/3/07 7:59 AM, Anonymous Anonymous said...

Hello!

Great Job!

Can I use this? how? Is there any instructions on how to deploy?

sorry guys, Im new to this stuff, I just want to try it in my local web server here at home..

thanks in advance...

you can email me: crack_stuwer@yahoo.com

 
At 7/17/07 7:35 AM, Anonymous Anonymous said...

Hi, does this component work with .NET? Are there any examples of that?

 
At 7/21/07 1:26 PM, Blogger scottm7 said...

Hi,

We have been using this component, and it works great. Thank you.

Unfortunately, the latest version of Firefox on the Mac (2.0.0.5) no longer works with it.

When you select files to upload, you get a "1023: Stack Overflow" error in Flash and number of "too much recursion" errors in the Firefox console.

The same thing happens on your demo page. If I roll back to 2.0.0.4, everything works fine.

I was wondering if you had any ideas?

Thanks a lot,
Scott

 
At 8/9/07 3:46 AM, Blogger Niels said...

Just want to post my solutions for uploading large files. This was also fixing the IO errors.

You have to change in the php.ini:

upload_max_filesize = 1024M (or more if you want to)
post_max_size = 1024M (or more, equivalent to the upload_max_filesize)

Also short_open_tag = on must be set in the php.ini, or you get errors.

Hope this will help some people.

 
At 8/10/07 6:00 PM, Blogger TheJackal said...

Does anyone know if it's possible to have the flash player resize/compress images before uploading? Or is that a capability that the player just doesn't have?

 
At 9/5/07 12:12 AM, Anonymous Anonymous said...

anyone able to capture the IOError event reliably to make second/third attempts at uploading a file? The first time the file failed to upload my IOError event handler captured it and I was able to call the upload method to make a second attempt at uploading the file. The second attempt should have failed again but my IOError event handler did not capture it. anyone having the same problem? thanks!

 
At 11/3/07 6:11 AM, Blogger Sudhir Kumar Jena said...

It would be really great of you if you could provide an ASP.NET webservice code for uploading the file. That would really be of great help.

Thanks
Sudhir Kumar Jena

 
At 11/6/07 3:20 PM, Blogger C said...

Hello,

Nice piece of UI! I plan to integrate this with a Java based site.

Do you call that url on every single file ? Does my java code needs to do something special on the errors ? I will start learning php to understand how your code handles errors...

 
At 11/7/07 2:16 AM, Blogger vonnhugo said...

Hi. Do you have a working example that uses JSP for server-side scripts?

Thanks

 
At 11/7/07 6:59 AM, Blogger Regis said...

This component seems to be a beauty, thanks for sharing it. Problem is I can't get it to work... The upload never starts... I have updated the file paths to reflect my server settings, set my upload folder permissions to 755 but the app still dies silently (it really gets stuck before the upload, with the upload button disabled and the progress bar not showing up). Any ideas?

 
At 11/8/07 1:54 AM, Anonymous Anonymous said...

greate !
my rails app is happy now

 
At 11/8/07 9:48 AM, Blogger C said...

I need more control on the upload.

For example:
1. only files that weren't uploaded before can be uploaded
2. only certain types(images)
3. only certain sizes( cannot be small and cannot exceed 10mb)

All this are check on the server side but I want to be able to read the response (HTTP Response) to get the result code from it.

How do I get access to the response ?

var request:URLRequest = new URLRequest();
request.data = sendVars;
request.url = _strUploadUrl;
request.method = URLRequestMethod.POST;
_refUploadFile = new FileReference();
_refUploadFile = listFiles.selectedItem.file;
_refUploadFile.addEventListener(ProgressEvent.PROGRESS, onUploadProgress);
_refUploadFile.addEventListener(Event.COMPLETE, onUploadComplete);
_refUploadFile.addEventListener(IOErrorEvent.IO_ERROR, onUploadIoError);
_refUploadFile.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onUploadSecurityError);
_refUploadFile.upload(request, "file", false);

 
At 11/8/07 11:28 AM, Blogger Cahlan said...

_refUploadFile.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, onUploadCompleteData);

 
At 11/9/07 8:05 AM, Blogger C said...

That worked indeed! One note, for those that are reading these comments -do not try to remove the listener in clearUpload.

One observation, I'm new to Active Script but dealt with many languages before, the lines below seem redundant. First creates a new FileReference and the second one overwrites that value to the one at the current index
_refUploadFile = new FileReference();
_refUploadFile = listFiles.selectedItem.file;

Lastly it anyone has an idea how can I make the successful uploads green and the invalid one red ?
mx:DataGrid seems that is not leaving me much options but please feel free to disagree with me.

cahlan if you want to take this offline would be my privilege. My address is theqmaster*at*gmail

 
At 11/15/07 2:52 PM, Anonymous rick said...

Hi thanks for the component, it's very nice.

i'm running into a problem though, i'm using Flex 3 Beta 2 and when i compile this and put it on my server, i lose files in the upload. It uploads the first 1 or 2 fine but the rest get dropped. The file sizes seem to be an issue, i've tested this with files around 1mb in size and this still happens.

 
At 11/16/07 4:20 PM, Blogger Ezekiel said...

Hi everyone,

Our server does not support php (we use mod_python for our backends). Do you know how easily the the backend (upload.php) could be rewritten in mod_python?

Thanks,
-Zeke

 
At 11/21/07 8:25 AM, Blogger Ezekiel said...

Nevermind about the mod_python. I was able to get access to a server with php support.

Your tool works very well, but I have a few questions:

Right now, I'm testing a couple things with the server-side php (like file size, file extension, etc.).

How exactly do you access the XML passed back by the upload.php script, using Flex? How can I see the success status, error message, etc?

You can email me at zeke*at*tradeworx.com or smigel.ezekiel*at*gmail.com

Thank you for your help!
-Zeke

 
At 11/29/07 8:39 AM, Anonymous Anonymous said...

Please forgive me I am really new to Flex/Flash. How would I incorporate this control into an ASPX page?

Thanks,
-- Joe --

 
At 12/12/07 8:41 AM, Blogger Jason G said...

I've only changed the _strDomain & _strUploadScript and have run into a problem.

Parse error: syntax error, unexpected $end in C:\wamp\www\FileUpload\upload.php on line 63

I found this by checking what was being passed with Fiddler.

Any ideas what might be wrong?

 
At 12/19/07 4:02 AM, Blogger Earth said...

it doesn't work ,I tried it on my localhost but no response... silence when i clicked the upload button./
Anyidea?

 
At 12/21/07 11:21 AM, Anonymous WebGyver said...

Thank you for making this example available!

It always amazes me how everybody wants everything for free, and then when you give it to them, it's never good enough.

Although I'm still a Flex newbie, and I could certainly use more help with a lot of things (including file upload), I'm grateful you provided an example.

We'll work out the details as we go along, to make it work for our particular needs.

Again, thank you very much!

WebGyver

 
At 12/25/07 3:28 PM, Blogger Dreamworks said...

10x 4 sharing

 
At 1/25/08 3:10 AM, Blogger vonnhugo said...

got it already: http://crackmyknuckles.blogspot.com/2008/01/uploading-files-with-flex-and-jsp.html

 
At 1/27/08 2:30 PM, Anonymous Fedele Marotti said...

Hi,
first of all thank you for sharing this great usefull component;
I've found a little bug: if you remove the first item of the datagrid when your list is longer than 2 and than (without do anything else) you try to upload your files, you've got an error, the application stops after the upload of the first file;

I've fixed it by commenting two lines of your code: line 126 and line 129.

I hope this is a usefull information.

Anyway... great work!!

 
At 1/27/08 11:59 PM, Anonymous Anonymous said...

hi, im new to flex. if this is a component how do i use it? im using flex3 beta milestone 4.. sorry for the dumb ?'s

 
At 1/29/08 12:26 AM, Blogger abhishek said...

how to upload file in flex and send to rails .
could u give source code .

 
At 2/2/08 9:30 AM, Anonymous sondangparulian said...

I know Why Get IOError, when uploading file to server,because your internet access using proxy. but I don't know Solution for this I have same problem IOError too :D when I using proxy in internet browser configuration,maybe must use crossdomain.xml does anyone have solution for this ??? And make upload file available using proxy???

 
At 2/19/08 9:13 AM, Blogger Taher M said...

I would like to add an information about the IO Errors that it can be caused by ModSecurity module in Apache and throws back a 406 http not acceptable error. to get it solved you can add .htaccess file to the script directory and to the destination folder for the file transfer that includes the following:


SecFilterEngine Off
SecFilterScanPOST Off


this will disable the ModSecurity module for that folder.

 
At 3/19/08 11:02 AM, Blogger Xyrer said...

Hi, this example looks great but I don't know how to put it inside my project, any reference I should read maybe? thanks for sharing, knowledge is power!

 
At 3/19/08 11:21 PM, Anonymous Anonymous said...

I have one file upload feature. This feature apart from uploading file, try to process the file also. From my server i am doing some validation and if validation fails I am throwing Exception. This is properly caught by IOErrorHandler defined in flex mxml file, but I am not able to retrieve the root cause of ther error message as IoErrorEvent object doesn't contain the error message sent from server. Can anyone please help how to retrieve root cause of io error.

 
At 3/20/08 2:22 AM, Blogger Taher M said...

You can add event listener on http status events like the following:

"YourComponent".addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);

then for the handler function you can process as per the following:

private function httpStatusHandler(event:HTTPStatusEvent):void {

if (event.status != 200)
{
if (event.status == 500){
mx.controls.Alert.show("Probleme d'écriture","Error");
return;
}
if (event.status == 404){
mx.controls.Alert.show("Fichier non trouvé","Error");
return;
}
if (event.status == 415){
mx.controls.Alert.show("Type de media interdit","Error");
return;
}
if (event.status == 401){
mx.controls.Alert.show("Acces refusé","Error");
return;
}
mx.controls.Alert.show("Erreur "+event.status,"Error");
}
}

Hope it can help.

 
At 3/27/08 8:41 PM, Anonymous Anonymous said...

Have you tried uploading from mac safari??I guess the event.Complete event is not triggered with safari.
any work arrounds??
Thanks!!

 
At 4/24/08 12:04 PM, Anonymous alex said...

i´m trayng to use your component but whe i run it from my sever i get this error:
-------------

[RPC Fault faultString="Security error accessing url" faultCode="Channel.Security.Error" faultDetail="Destination: DefaultHTTP"]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()
at mx.rpc::Responder/fault()
at mx.rpc::AsyncRequest/fault()
at DirectHTTPMessageResponder/securityErrorHandler()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/redirectEvent()

---------
can u help me?

 
At 7/10/08 2:14 AM, Anonymous F.Vervelde said...

thank u very much.
F.Vervelde

 
At 8/18/08 8:34 AM, Anonymous mhartung said...

Hi,
- is that tool under any kind of license and when which one?

- will that tool still work with Flash 10 ?

- and is there indeed the source code around, i did not stumble over it yet.

Thanks :) greetings mhartung

 
At 8/19/08 3:34 AM, Anonymous martin said...

Hi,
that is kind of what i was looking for but i have some questions.

- Will that thingy still work with Flash 10 ?
- What kind of license is used, so what are the legal ways to use it?

Thanks, Martin

 
At 9/2/08 9:13 PM, Anonymous Anonymous said...

So if I have this:

com:FileUpload id="uploader" ...

why doesn't this work?

uploader.addEventListener('uploadComplete', ..) ???

 
At 11/5/08 8:50 PM, Anonymous Anonymous said...

its great!
where can i download this source?
thanks!

 
At 11/6/08 10:50 AM, Blogger Mete Hanap said...

Dude!

This is the kinda stuff that always makes my day.

You Rock!!!!!

 
At 11/9/08 3:18 PM, Anonymous Anonymous said...

Really nice :)

 
At 11/10/08 6:03 AM, Anonymous Anonymous said...

Hiii i am not able to UPloadPNG files on MAC,which has version 10.05 any ideas please some one can help me

 
At 11/22/08 4:14 AM, Anonymous Anonymous said...

I got an error like this

Error #2044: Unhandled uploadIoError:. text=Error #2038: File I/O Error. URL: http://localhost/weborb/securityidsystem-debug/upload.php

I already set the permission of that script to write the file.

By the way im using IIS and PHP 5.2.6.

 
At 11/28/08 10:27 PM, Anonymous YhwhDesign said...

Any help with this would be great.

I want to take your component, and add it into a contact form. Thats part one of the idea.

the second part is I want it to only show if the viewer clicks on 'upload file' button.

other wise it would stay hidden.

any help would be great.

thanks
YhwhDesign

 
At 12/3/08 12:45 PM, Anonymous Anonymous said...

This worked like a charm! I use a .ashx (http handler) through IIS and couldn't be more happy with this front end.

Kudos...

-
jm

 
At 12/19/08 2:45 PM, Anonymous Anonymous said...

Source code = Right click > View Source. It's not too difficult

 
At 12/26/08 6:13 AM, Anonymous Anonymous said...

could not upload, there is always such an error:Security Error in uploading file.

 
At 12/31/08 5:24 AM, Anonymous karlpox said...

the mxml+php is working fine and when i run the project and upload some images it says "files has been uploaded" but it wasnt uploaded. how do i fix this?

 
At 1/6/09 4:04 PM, Anonymous Ryan said...

Hey, thanks for this wonderful concept, but unfortunately I can not get this to work... is there any way you could explain it a bit better?


Im not complaining! :)

 
At 1/9/09 6:53 PM, Anonymous Anonymous said...

@karlpox:

try checking the $_SERVER["document_root"] in the upload.php. Maybe it isn't pointing to the correct folder (i had the same problem and i fix it with that).

regards,
N.

 
At 1/10/09 4:30 AM, Anonymous karlpox said...

yep that did the trick thx. but i got another problem everytime i upload 3 or more images my apache lags. is there something wrong with the php file?

 
At 2/15/09 7:22 PM, Anonymous jom said...

thnk.

 
At 3/17/09 7:13 PM, Anonymous rhosman said...

That is a beautiful piece of UI but I get a "Error: Security Error in uploading file." when I try and use your demo.

 
At 3/23/09 9:29 AM, Anonymous Anonymous said...

Any one know how to solve a problem with flash 10 ?

 
At 3/25/09 6:53 AM, Blogger moon said...

Wonderful concept, but having difficulty.
shows error "Security Error in uploading file" on upload click.
Would you what parameters need to change as I m using aspx page instead of upload.php.

 
At 4/1/09 6:49 AM, Anonymous Anonymous said...

Hi, thx for this component but i got a problem...

The upload.php didnt work :

Parse error: parse error in C:\Documents and Settings\DUALSILVER\My Documents\Flex Builder 3\upload\upload.php on line 63

the line 63 is the end tag of the php files: ?>

please help me

 
At 5/5/09 5:05 AM, Anonymous Anonymous said...

Wonderful tutorial. Can anyone have a code for this. if anyone have plz post that

 
At 6/4/09 12:18 AM, Blogger snorkel said...

There is a case bug in the IOerror event handler.


[Event(name="uploadIOError", type="flash.events.IOErrorEvent")]


does not match the name here:
var evt:IOErrorEvent = new IOErrorEvent("uploadIoError", false, false, event.text);

The o in IO is not capital, and because of this the event will never fire.

Just make sure the case matches on the event name and then the IOerror event will fire.

 
At 6/4/09 12:20 AM, Blogger snorkel said...

Has anyone used the component on firefox under 64bit Linux with Flash 10?

When I upload something the progress bar does not work at all. Works fine on windows though.

I thought flash was not supposed to have any issues with browsers like this?

 
At 6/8/09 7:03 AM, Anonymous youden666@hotmail.fr said...

Hi, awesome component ;)
i would be pleased if you could give me the code for the function that permits its minimization on click on the right button. I would like to use it in a video player.

Thx in advance.

youden666@hotmail.fr

 
At 6/18/09 12:44 PM, Anonymous Anonymous said...

Even though php may send a "false" result, the flex code does not do anything with it.

One idea is for php to write a log of the results. Then after all files are uploaded, flex can call a httpservie to read that log and show all the success/failures to the user.

-Cheers.

 
At 6/18/09 11:02 PM, Blogger abhishek said...

hello frnds,
could we start to upload all files at a same time instead of one by one?

 

Post a Comment

Links to this post:

Create a Link

<< Home