Flash 8 File Upload Download
We have completed an example of one of the new feature in Flash Player 8, the File Upload/Download – FileReference. The current demo have a parameter to control the MAX size of the individual files that can be uploaded. This value is changeable via the FlashObject variables in the SWF embedded html. The current demo is also configured to save the uploaded files to a directory, “userUploads”.
Sypnosis
Flash Developers have been asking for File Upload download functionality in Flash for a long time now. This time round, Macromedia finally decided to put in this functionality in the Flash 8 Player. And the better news is that the API that has been provided allows for uploading not just one but multiple files as well. This example shows how multiple files can be uploaded to the server using a simple upload queue. The upload queue groups together multiple upload requests and provides unified progress events for the entire group. This helps us provide the user with a single progress display even when uploading multiple files.
The possibilities this opens up for flash RIA’s is amazing. Imagine populating an entire photo gallery with a Select All + Upload combo. Flash developers now not only have file uploads but the usability of multiple file uploads, which beats other current implementations as well.
FootNote
Express Install
This example is combined with the Express Install feature of Flash Player 8, whereby if your Flash Player vesion is earlier to 8, it will try to do an Express Install.
Image Preview before Download
There is also an Image Preview before you Download a particular Image.
ColdFusion
The file drop routine can be done by any Server Side Script, for example, there is a C#.NET upload script. Our example uses ColdFusion for dropping the uploaded file to the server and the CF code was just one single line
Here are the corresponding upload Routines for Reference.
C#.NET
Via Shunjie Blog
string saveToFolder = “savedFiles”
private void Page_Load(object sender, System.EventArgs e)
{
HttpFileCollection uploadedFiles = Request.Files;
string Path = Server.MapPath(saveToFolder);
for(int i = 0 ; i 0)
{
string newName = F.FileName.Substring(F.FileName.LastIndexOf(“\\”) + 1);
F.SaveAs(Path + “/” + newName);
}
}
}
PHP Code
Thanks to Tink for helping out with the PHP Code.
Comments
unless there’s a security setting change you need to make, it appears that the player doesn’t like files that are on a network device (that is, their not local files).
it will browse to them, but always display 0 k for file size and give an error when your “Upload” button is pressed. hopefully something that will be fixed before release…
g.
WinXP Pro, Firefox 1.0.6
Wonderful news (multiple files)
Do you plan to show some of the as code?
Flash 8 File Upload and Download
Can you post the FLA and CFM so we can get at it? This is way cool! (or post offline!)
I can see that Flash Uploads and Downloads Files. Can Flash 8 write to file as a standalone application?
Hi
Please tell me that this file upload and download example in flex how we can implement ..
Is there any chance of someone posting a PHP version of the viewFiles.cfm file please?
And Asp Example when???
Flash 8 doesn’t support animated gif.It consider the animated gif as a still image.
I can see that Flash Uploads and Downloads Files. Can Flash 8 write to file as a standalone application?
I don’t think flash can write to a file, however the php is very easy for that so the both combined could do that job easy.
I am not able to create a
HandCursor on the context Menu.Please guide me
Thanks
I dont know if anyone still needs this, but the code for viewFiles in php is:
bc[as].
Flash 8
Il vient de sortir et il contient un paquet de nouveautés : Macromedia
Pour en voir quelques unes…
hey,
when i try to export movie from fileuploaddownload.fla, i got this error:
why? i didn’t modify the folder
somebody could help me???
thx anyway, pretty good job from oinam
Can i get the FLA for this please, it would really help me out ?
Thanks
hey, here’s a bug, if you select several files (with a weight over 50kb), it uploads nayway…
thx anyway, pretty good job
Thanks for posting these examples!!
I can’t get the aspx page to see any files in the Request.Files collection? Any tricks to get this working?
Would love to see the ActionScript for dosplaying the uploaded file’s filename at a minimum, but the FLA would be supreme
Great article, by the way.
Mike G
Can you upload without OpenDialogWindow?
i see that this example covers preview from the server before download…cool
but what i need to do is the complete oposite preview from the users disk before upload is this possible ?
Some answers to the questions here:
Flash Player 8r22 has a bug where on Windows, files that are not on your local device cannot be uploaded. The Mac player doesn’t have this bug.
Regarding the dialog box for selecting the file to upload or a location to download, you cannot avoid the Flash Player bringing up this dialog box.
Full FileReference documentation is here:
http://livedocs.macromedia.com/flash/8/main/00002204.html
cant get the download section to work with the php code above, anyone here get that to work with php. Any help would be great. thnks
Any CFM or CFC Example?
I’m using the php method and I got it to upload fine but the download section doesnt work, in the “select file for download” area it says undefined (NaNkb) any ideas what I’m doing wrong?
Can I get the FLA file to understand this better?
Thanks
Please!!!!
I can’t get the flash upload to work. All I get is a login prompt asking me for username/password. Why??? In a desperate atempt I even gave INET_USR administrator priviviliges!!!!
Does any no whats wrong?
Can you preview the selected images before uploading in flash 8?
I downloaded your example and got it to work with CFM in IE but fails to upload when using Firefox.
Your online sample works with Firefox, what am I missing with your example on my host?
Do I need some sort of policy file or other security measure for non-IE browsers? Frustrated big time with the Firefox issue, works in IE as it should but not Firefox. The download even works fine with Firefox just the upload aspect is fubar.
Any help is much appreciated, thanks.
Is there any way how to pass more information with the uploaded file?For istance I would like to make an description TextBox and pass value of the TextBox with file to the server.
Use this instead for the viewer portion. The other PHP doesn’t echo the proper XML
bc[as].
hi, got the same question as andreas. is there a way to preview local images with the new flash 8 objects?
hey this is awesome,
I’ve created a corresponding viewFiles.php for those who are like me and love php.
you can download it here: http://blog.digidogstudios.com/fileupload_viewfiles_script.zip
hope that helps!
Has anyone ever tried uploading a video. .mov, or even .wmv?
I mean every single tutorial seems like it is a re-hash of the one Flash 8 has in it’s sample file. Meaning only images are being uploaded. Can someone help me figure out how to upload movies.
Thank you. I have got it to where it is recognizing the file extentions
does anyone have the PHP version of the viewFiles.cfm
It seems it was posted above but all I see is bc[as]
Hi,
Great example of filereference! Does anyone have a working viewFiles.php ?
I can only upload sofar.
Hi Pixelone,
The filetype was restricted to Image files as they are rather harmless. You can allow any filetype to be uploaded. I hope you have checked the source file for the same.
Is there a way to add a delete function, so that someone can delete the useless files from server?
russland, thx a mil! This works like a charme
I’m using testing the upload feature with customers now. My DSL customers are getting a Flash I/O error after about 5 or 6 files. My cable customers are having no problem. Anyone have an idea about this? Is it the connection type or a coincidence?
Uhhmm, sorry ignore my last post, i meant Steven Hargrove, thx a mil! This works like a charme
Resumable File Downloads with ASP.Net
Peter AitkenHas this ever happened to you (I bet the answer is
I can get the FileReference object to upload a file thru a C#/.NET page but i’m running into an interesting issue. While the file uploads correclty to the server, there is another function called in my .net page to save the path to the database. For some reason it doesn’t save the path to the db after uploading the file.
Does FileReference somehow stop the activity of the page the moment it senses the upload? Anyone else run into this issue?
I’m receiving I/O error from flash when I upload files larger than approximately 15-20MB using the C# script on this page.
Can anybody shed some light on this, as Im rather inexperienced in C# and .net.
My first thought was that the server script timed out during uploading to server. Other testing on my own webserver showed that was not the case.
Got clues?
Lar, regarding your Oct 14 Firefox post: this may be happening because you’re trying to use session variables. I’m having the same problem with PHP.
The example uses javascript to pass variables to the Flash file. IE continues the session, passing it directly to the display file, but Firefox / Mozilla don’t do this. This could be a security bug in IE, but that’s what makes it work.
One workaround would be to try and substitute the javascript for HTML using param=flashvars. I haven’t tried this yet, but it may work. Let me know how it goes.
thought i ougt to mention my discovery. I had problems uploading files over aprox. 20 mB
A friend told me theres a filesize limit set in the .net framwork. in the file machine.config.
Now back to nerding……
I try to implement the multiple upload in an ColdFusion Application. I am working with fusebox. I sett the Upload URL with some Variables (looks like http://www.test.com?fuseaction=test.upload&Variable=1&showerror=true)
After submit it looks like it looses all Variables after the fuseaction! I need them to create the correct upload path dynamic.
Has anybody experienced the same problem? Any solutions?
Does anyone know how to resolve the proxy problem?
Why is it impossible to download the last item in the list?
Is it a bug in the list component?
I have that prob with me and apparantly it bugs also on this example:
>>> http://labs.oinam.com/flash8/fileuploaddownload/
I am trying the .net script, but it says Error HTTP 500. Does anybody has a .net sample working???
8 hours in a row trying to make this work!!!
Help Please!
Had it working locally, and moved it to the server. Now files will upload successfully, but will not be veiwable in the download preview window. They look fine if downloaded and veiwed normally. Any Ideas?
I get Security Sandbox errors – I put System.security.allowDomain(“*”);
in my code but still I get the error –
Any Help -
The URL in FileReference.upload(url.php) does not recognize $_SESSION variables (always undefined even when the session is set) – anyone else experience this or have a solution?
Nice demo!
For those that are intrested, you can see a live version of flash 8 uploading for photosharing here:
http://www.bubbleshare.com
(go to the enhanced uploader — but be running firefox or Mac, otherwise it’ll bring you the the activeX uploader)
Nice demo.
There is a little error in the source, instead
Right now the script skips the check for the next file if invalid filesize is found. Also it will be nice if you set
multipleSelection=truefor “uploadFilesList” and use uploadFilesList.selectedIndicesto remove only selected files from the upload queue.
Thank you for sharing this!
Richard, the only way to pass _SESSION variables is through GET. Pass them through to nextURL.
If you’re using PHP, you can set up nextURL like this, before opening the javascript tag:
$passurl=’upload1.php?p=’.$p;
Then pass the php value within the javascript tag like this:
var uploadid = ‘\
I used the source file but Iam getting error..Iam not a pro in flash..but I need to do this task..I need multiple file upload and got the source from here http://labs.oinam.com/flash8/fileuploaddownload/
and uploaded to http://lismardts.com/demo/index2.html but IAm getting error..what exactly I need to do can anyone help me with this one.
Very nice script – thanks a lot Braj!
We’ve modified it to do just upload, and are using it at http://fotojuice.com.
This version uploads multiple files, passes session variables, and works in IE as well as Firefox. I was getting server errors due to PHP setup limits, but that too has been taken care of. Thumbnails are made using PHP’s image functions based on gdlib.
Some more information would be great.
I am trying to upload text and dbf data files, and at the moment have to use FTP.
I’ve tried changing the code to read
but am getting a securitySandboxError. Any ideas how to rectify this? Images work fine. Also, are there any technical limitations to the filesize that can be sent (by the player, not maxFileSize)
Simon,
There is a 100mb limit on the files that you can upload in flash player 8. And the player becomes non-responsive if you try such large files.
Security Sandbox error sounds like a cross-domain issue that should be resolved by using appropriate crossdomain policy files.
Working with ColdFusion, Fusebox:
Is there a way to give back an ‘message’ about if the upload was successfull or not. In the file with the i tryed to set a FlashVar:
… but it didnt work! Has anybody a solution?
Anyone know how to create a Perl code for this?
Thank you for putting the logic together for this. Nicely done. I was dreading having to spend a few days putting this feature together myself and having to debug it (can’t stand forcing our clients to use the java applet). It seems you packaged it very well.
I thought you might be interested that I found a minor bug in the logic and thought I would would give you the code change for the fix.
When you choose multiple files from the dialogue box and a few of them are oversized files from your preset maxFileSize variable it will often allow the oversized files into the que for upload.
Old code
New Code:
evidently a NaN can be thrown after the firrst discovery of a large file for some of the other large files. This catches it.
Also the original loop value of (i) would be too high to splice out multiple large files so I drop the values of (i) and (n) after each splice.
Thanks again. Great work!
Has anybody thought about security? I made an application which is password protected. After login the user can upload files. But how, can i pass the session to the flash without showing all the information in the sourcecode! Anybody a good idea or maybe working on the same problem?
Does any body know the Server side script, if i use Appache Server with Oracle DB.(I need a code in PL/SQL)
I get an HTTP 500 error when I try to upload files using the PHP code provided above. I CHMODed the directory to upload files and can’t figure out the problem. I can’t see uploaded files either.
Hi!
I have a problem with upload. Is it possible to get answer from “upload.php” -file during progress or together with onComplete to Flash?
Like this:
// file is uploaded and I want other information from php to flash…
$answer = “Database updated” ;
print(“&answer=$answer”) ;
So if this is possible, how I can get it in flash?
Nice functionality!
Anyone allready made an ASP version?
I’m trying to use a site that uses flash and copy the sorce on it and I can’t could you please get back with me on if I need a program to view the sorce in flash. The only thing I can do is Print to file and I don’t know how what exstention to use when I print to file. Can someone please explain to me what i’m doing wronge or is there a program that I need to use to view sorce on flash sites. I do have flash 8 if that helps.
Thank you for your time my email is above
Finnally I’ve got the ASP version of the files here!
John> Can I have a copy of the ASP files?
Thanks!!
You can download the ASP files at Lolobal
Gr. Davy
I download the files uploaded to my website in the wwwroot but if I upload a file I get a http 500 error
Davy> Thanks! Got’em..
However, im having problems using aspSmartUpload instead of aspUpload which costs money. Has anybody else tried that?
Koen> Try to use the formTest.html file and upload from there. That way you might get a more precise error description. Internal server error could be path related.. Try skiping server.Mappath and use the full path instead.
**********Allowed number of uploaded images**********
Does anybody know how to limit the number of uploaded files in an upload session?? I.E. 30 at a time??
Thanks in advance
Does anyone have advice for modifying the source code to allow multiple file select for downloads? Would this be an easy or complex change? (I’ve already modded the source for filetypes and size limits). It would really help for my application — I don’t need the image preview feature, but do need multiple select downloading.
Has anyone got this working in a J2EE environment? I’d like to get it working somehow with a Servlet. Any ideas?
I downloaded the source. I test it on iis i keep getting “error 405″ can anyone help with that
Thank you very much 4 this excellent piece of code and functionality…
We will use this 4 sure
THANKS! this looks very cool, and has been helpful as far as understanding whats going on with file uploads now. I’m using the cf version. Running into a http error 403. I browsed and someone on the MM forums had an non similar setup and issue, but was also getting 403 and pointed to articles reguarding phpsuexec and so, as instructed in the articles, I went and made sure all folders were max 755. Still no luck, and formTest.html gives me the error:
Method Not Allowed
The requested method POST is not allowed for the URL /uploadFile.cfm.
Apache/1.3.33 Server at mydomain.com Port 80
Any clues? i cant find anything about it anywhere.
Thanks,
-thummper
Hi there, i have problems with the asp version i am using the aspSmartUpload but flash get an error called hhtpError 500. I am using iis and i have tried the aspSmartUpload form and it worked fine but with it gives me that error, any idea???
thanks
Do you know how to compiler Flash in C#?
Thanks
google is the good search engine.
How do you get by sandbox security error when this is used by a macintosh client in various browsers.
Hi,
I have downloaded the source and placed in on the web,
I made the folder “userUploads” writeable for apache
I don’t get any error’s bud uploaden dosn’t work.
Do i forget something ?
Is there an readme file somewhere ?
Please help me with this one.
I need it for my shop.
can this be modified to work locally to pull in the URI of a local folder structure?
Easily the best I’ve found so far..
ASP VERSION : i have an http 500 error and my file is not uploaded, did someone found the bug ?
I had changed some coding around to accept media files and i am having issues refining the coding and getting it to work.. any suggestions?
The flash upload doesn’t show when the user is behind the proxy, but only in IE, in FF works fine. Any workaround with IE?
I’m getting “Unexpected File Format” when trying to open the fla. I’m using MX2004. Please help!!!
Has anyone figured out the ASP functionality? I am getting the following error:
Persits.Upload.1 error ’800a003d’
Wrong Content-Type. Make sure you have included the attribute ENCTYPE=”multipart/form-data” in your form.
hi,
don’t you know is there any solution for the ‘big’ file upload bug? (when you want to upload file about 20mega the player gets unstable, and open the ‘script run too slowly’ alert window).
I hoped that it will be changed in the player 9, but unfortunatelly not
still doesnt work well (player 9 with ie6)
it’s a shame, but if it still doesnt work, we must go back to the simple html+javascript upload
thx,
balage,
balage@technoart.hu
ei guys i have posted it in the forums, il just repost it again here and hope som1 cud help me..
-in the website example, before someone can download the images, there must be a user login verification.. how can i do that? is there also a way to have a verification b4 someone can upload a file?
-is it also possible to place all uploaded files in an ftp server? coz i have noticed in our server that the userUploads can be viewed by anyone.. huhu:D im planning to make it more private and secure.
-i have set the maximum file size to 10mb and yet the upload tool only upload files which are less than 1mb.. is apache server configuration concern in this matter?
ei guys, i have figured out some of my questions.. tnx for the replies anyways.. well can this flash object support drag and drop capability. for example i have a file on my desktop then i will drag these files and drop it on the upload window..
can i do multiple downloads for the files i have chose? and then create a zip file..
Been reading comments on how to get a message back to Flash from the PHP to say when the file has uploaded properly (or not). I had this resopnse from a forum I posted my question on – Have a look in livedocs
http://livedocs.macromedia.com/flas…art4_ASLR2.html
actionscript 2.0 language reference->actionscript classes->FileReference->onComplete (towards the end a couple posts regarding returning customised http errors)
you can return certain rarely used http codes to indicate certain states in conjunction with onHTTPError.
I’m using this now and its very useful!
This is a really great resource; thank you for making it available. I’m semi-flash-ignorant, and trying to figure out how to use this file and a) pass a variable (an “uploadId”) to php so i can update the database once the file is uploaded and b) send user to a different URL after the file is uploaded. Can anyone give me some guidance? Thanks. /skc
Hello,
i found this script two days ago and i already installed it on my server. Meanwhile, with the php version is very easy to bypass the prohibited files. Malicious people could send executables scripts to the server and then execute them remotely. In fact, even if you filter the extensions, once you want to upload a file, you click on “browse” and then you won’t see your malicious script because it will have a prohibited extension. But, if you give the name in the “file name” field, the forbidden file will appear into the “upload” window and then you can upload it. It will bypass the “allowed extensions”. Then, if the directory is marked as “script executable”, the bad guy can call his script which will execute on the victim’s server. I would like to know if somebody has already a workaround for the php scripts, which will check by itself the allowed extensions before sending them to the server.
Thanks for reading.
Strotti
Can flash read files in a directory?
I would like to make a photo uploader that allows the user to choose a local folder and then it displays thumbnails of the photos and allows the user to choose which ones they want to upload. I have seen this done in Java, but I don’t really want to work in java if at all possible.
I guess basically, I am trying to get around the whole “operating system” open dialog box for the FileReference feature. Any thoughts?
Hi People,
Going through all the information on this page, is starting to make my head hurt. It seems like it is about time that some-one compiles all of this, and starts a clean thread, or provides an updated version of fileuploaddownload..?
What do you think?
There are too many questions, and not enough answers…
Hi,
Tried to download the source file but your link is dead. How can I get the source file?
Thanks
Nice site. I had a bit of trouble with loading some of the pages, but maybe that’s just because I use a non-standard browser.
http://phentermineaad.blogspot.com/ Warm regards Tom Green!
I am wondering if it would be possible to provide an updated link to the source files, since the original links are dead. Thanks.
CSABA, I have provided a BackUp download link above, btw, the demo is not working as I’m unable to foot the bill for hosting just for this one. I’m though planning to move it to one of our server though (it was alone on a virtual dedicated server).
“The current demo have a parameter to control the MAX size of the individual files that can be uploaded”
thank you for telling me this!
I can confirm the download links are not available.
Hi, i need the source file. It is very important. Please update the link. Thanx.
Here’s the C# code if your backend is asp.net instead of PHP:
HttpFileCollection files = Request.Files;
System.IO.BinaryReader br = new System.IO.BinaryReader(files0.InputStream);
byte[] bytes = new byte[Convert.ToInt32];
bytes = br.ReadBytes(Convert.ToInt32);
string fn = files0.FileName;
string path = Server.MapPath(“uploads”) “\\” fn;
FileStream fs = new FileStream(path, FileMode.Create);
fs.Write(bytes,0, bytes.Length);
fs.Close();
I download the php code but I have problem upload. After the upload is complete when I check the file there was no file that I upload. Can you help me to solve this porblem.
Hi,
When opening the .fla file in Flash 6.0 I get a error saying: “unexpected file format”
Any help would be greatly appreciated.
Is there a way that the content that is written to the page only shows the upload pane and not the donwload pane?
I just want to have the upload pane visiable and operational.
Also is there a way to know how many files are being submitted by the upload textarea so that you can loop through them?
Flash Player 6 have no support for FileReference and thus it was not an FLA created during the Flash 6 days!
I also tried to view the fla in Flash 5 but I still get the same error: “unexpected file formatâ€
Is the file corrupted?
regards
oliver
Hi,
I’ve an issue. I’ve a flash uploader to upload multiple files(pdf, doc) to a folder in the server.The upload is working fine. I want to download the files to my desktop using the core ftp. But, I see the permission of the folder as 600 and I cannot download them to my pc either. So what’s wrong and how to fix it??
@Kalai – I think you have said the answer yourself. It is an FTP issue and flash or this file upload/download module have nothing to do with it.
Yep, I agree, now am fiddling with ways to change the file permission in php, i.e after uploading the file to the specifica folder with 777 permission, am trying to change the permissions of the files to 777..
Still no luck.. let me see..
Anyway thanks for the responding
I ran into the same problem with the sessions not being passed and came up with a solution that I’ve posted.
My solution is in Rails, but should be similar with other web frameworks, you can find it here:
http://blog.overlay.tv/articles/2007/05/07/flex-2-file-upload/
Hi,
Well, I was able to ix the ftp issue, what I’ve to do, is call the chmod command for the files being uploaded. chmod ($uploadFile, 0777);
That’s it…
but now i face one more issue. I just want to list the files (SORTED – either date or name) in the rich file upload – destination folder (tree view component). Is there any way to achieve this?
Thanks
My implementation of this is working flawlessly in IE but it’s not working in Firefox… I have done what the prior poster suggested which is “substitute the javascript for HTML using param=flashvars”. I am embedding with embed and param tags, no JS.
In firefox when i try to upload the progress bar goes all the way up as if it’s transferring but the files never appear on the server. When i try to download I get a flash dialog window “An IOError occured.”
Does anyone know what the problem might be?
Jason: check out my post above and the article I link to (post 117). In firefox the flash file upload gets a separate session from all the other requests, which is what was causing my troubles.
Not sure if you’re having the same problems, but if you are check out that article because I have a solution in there.
Hope that helps.
Thanks Alex for your c# code, it helps me a lot with Flex.
The URL in FileReference.upload(url.php) does not recognize $_SESSION variables (always undefined even when the session is set) – anyone else experience this or have a solution?
To solve session issue in PHP I dont call session_start() in script that process upload request, so to you keep your script safe, make another security check, with a hash for instance
Please, I have the same problem with 1MB limit, even though the web.config (ASP.NET) is set to much higher (and besides, the default is 4MB).
I’ve managed to determine that if the file is bigger than 1MB the upload script isn’t even run at all. It is only run if the file is below 1MB.
Anybody have an answer for this?
Hehe… Time heals all wounds. I found the answer.
I’d configured error handling in Global.asax, and it normally redirects to an error page, but in this case, obviously, the only “one” who would see this error page would be the flash app, and it was satisfied with the execution of this page, so hence, no error, no (visible) redirect, just no file.
Fixed.