The new FileReference object enables you to upload and download files using Flash 8 and a server side script (required for upload only).
Here is an example I put together for the forthcoming book by friends of ED titled ‘Flash 8 Upgrade Essentials’. In the chapter I walk through the ActionScript file and FLA and explain how it all works. The other authors on the book are Matt Voerman, Craig Swann, Glen Rhodes, Todd Yard and Guy Watson.
The book should be out early November so save your pennies!

That is the nuts! That’s so cool.
oh. and gimme the bloody source.. flash 8 is released now
how does the upload/download progress work?
FileReference fires events that you can set an object to listen for.
Its very much like MovieClipLoader.
Obviously a lot of people are quite happy about this new feature. Is there anyone out there as disappointed as I am about the fact that you can’t select several files at once in the dialog box?
Okay, now the Flash Player is capable of doing something which before had to be done by the browser, but to tell the truth, it doesn’t help me in varios of my projects because of its lack of ‘multiple selection’.
Notice that in the Browse box for saving, it fills in the filename without an extension but give the file type as “All Files (*.*)”. Is there any to get it to show that I’m about to download a ZIP file? In the upload, it lets you choose an “Image File” or a “Flash Movie”, but there’s no way of knowing what Image types are acceptable. I guess I’ll have to wait for the source/book to see your implementation, but maybe this is a problem with MM’s component?
Nice work indeed, pretty neat stuff – except I uploaded one 45byte GIF file and one 5.35Kb GIF file and they both measured 45Kbs abd 535Kb in size – might be worth tackling?
not source until Flash 8 is released???
thank you.
very usefull.
Sorry not source until Flash 8 is released?
thank you
Mani, you’ll be extremely pleased to know that in the example i have used FileReference, which has the functionality to upload and download a single file. But FileReferenceList has the functionality to upload multiple files.
Adam i don’t believe it is possible to change what is shown in the ‘Save as type’ field, but you are able to specify the file name of the download.
‘Image File’ and ‘Flash Movie’ are descriptions i’ve specified, along with the file types users are allowed to upoad. The user will only see the file types allowed when they browse their OS, but you could display whatever you wanted in the ‘Files of type’ field.
And sorry alex no source at the mo.
[...] Files Flash 8 File Upload Example Now this is SWEET! Simply put, check it out. This entry was posted on Tuesday, August 16th [...]
How is upload made using ColdFusion (CFML)?
I was just wondering, since this is a flash player feature are developers going to have to upgrade from MX2004 to get the file upload/download components and classes.
I guess so?
Wiiliam, i know absolutely nothing about ColdFusion, but here is a simple ColdFusion script for uploading a file.
Ryan, all end users will need the Flash 8 player installed. I don’t believe you will have to upgrade your IDE as you could create a Flash 8 SWF with open source tools. That said for how cheap the IDE is for what you get, i would definately recommend buying it.
I love the file info that comes up before uplaoding! AWESOME!
Is there any ASP version of this thing around, i really need this for my next project.
Flash 8 File (multiple) Upload Download Example
Wow!! thats great, upload and download will be a great surviover for us
Any chance of posting the source now that Flash 8 has been released?
Well, flash 8 is now released. I’ve tried testing an upload with the new filereference however I get a sandbox restriction and have a policy file in place that allows all domains. Can you release the source now since 8ball is here?
Flash 8 is available, any chance the FileReference source will be made available soon? Thx.
flash 8 is released can we have the code please?
Very Cool!
Where can I download a working version with php code instead of coldfusion? Would it be possible for you to post it? Thanks.
I apologise for the slow response here. Things have been a little hectic recently. I made this example for friends of ED and therefore the source will be available on their site once the book is out.
I will upload 2 examples tomorrow with the full source, or for now you can view the presentation i did at London MMUG last week at http://www.tink.ws/mmug (use your cursor keys to navigate).
Well that was a waste of my time. Take the link off unless you intend to put up the source.
Charming!
Your saying that developers shouldn’t show any their work or experiments unless they provide the source?
Anyway, this example was done for a book, which is clearly explained in the comments above, so the source will be free and available, but from the publishers site, once the book is released.
Because of this i created 2 other examples with source (also expained above) for people who wanted the source asap.
This is cool, but pointless to the developer as there is no source available. Thanks anyways..
As metioned above, this example was done for a book, so the source will be free and available, but from the publishers site, once the book is released.
Until then I added the follwoing examples with source.
FileReference Source
Anyone find an ASP script for this download component yet?
I’ve asked a bud of mine who works in ASP and was told you need to use components in ASP to upload files, you can’t just use a bit of script. I’d be interested on someone confirming this as the case.
You can upload in ASP using pure script. But it’s a mess of code.
I havent got flash 8 yet do I have to pay to get it?
You can get a 30 day free trial from Adobe, but then you’ll have to pay.
Ok thanks
Thanks Tink, keep it up!
.
And don’t let those frustrated geeks like Dan and Developer get to you
@ 3221314: ASP needs components to upload files (a good one is ASPUpload). They usually cost….
I’ve you use php it’s free and easy; just one line off code:
i meant ‘if’ (not i’ve)
You do not need a component to upload files via ASP
I have used http://www.freeaspupload.net/ with no problems, no mesy code just use the include file
I set the file type display,then download a file which be renamed.The file’s type can’t be distinguish
[...] que comprobéis vosotros mismos que lo que digo es verdad: http://klr20mg.com/?p=57 http://www.tink.ws/blog/filereference-example/ (en esta, os podréis bajar un ejemplo que, despu [...]
OK, I see someone has gotten this to work w/ the FreeASPUpload that’s available. Do you have a code snippet to share?
I freakin’ hate ASP, but I don’t have choice for what I’m doing for this client (nor am I or do I want to be an ASP ‘expert’ either). I can get the FileReference to upload to my script on the server, but that’s about it. The documentation for the FreeASPUpload sux, and the class seems to be hard-coded to use naming that’s inconsistent with the Flash naming in the HTTP request.
ANY help with this would be greatly appreciated…
Good Logic For Upload .
Pls Send code for this
Hey Dok, unfortunately I know bugger all about ASP.
Mayur, all the code is in the book or you can download the example from the friends of ED or or can view and download the files from my presentation ‘A Round Trip with FileReference‘.
where can I find the sourse of the upload examle ty …. post it we need it we have to learn because Im not so good whit AS
With fear of repeating myself…
Bagpiper, all the code is in the book or you can download the example from the friends of ED or or can view and download the files from my presentation ‘A Round Trip with FileReference‘.
Great work, Tink.. You had posted up a link for a ColdFusion page example, but the link doesn’t lead anywhere anymore. Any chance of putting this up again? I downloaded some of the other examples which are featured in your book – some really interesting techniques indeed…
Ignore my last post, I worked it out… for anyone else you do it like this:
please give us the sorce!
With fear of repeating myself… errr again…
All the code is in the book, or you can download the example from friends of ED.
HEY! STOP!
This is how you get it:
go to the friends of ED website by following the link in the post above. Click on Downloads and choose the bottom download, the Appendix one. Unzip and look for fileReferenceExample.
The source is in there.
Hi there!
Nice work! Although I am having some problems and was wondering if you could help me.
I am using your example to upload a file to my server using flash. But I need to change the files name when is fully uploaded. Lets say, if at the clients side is one.dat I must upload it to my server as two.dat. How could I do this and what modifications on the code must I do? I tried to use rename in a php file but the “rename” must be during the uploading.
Thanks.
Cheers.
Leo.
yooooo…. developers begging for sourcecodes, then what is you guys developing… the flash help and some brains can get you everywhere… respect to tink
Hi, Tink.
Thank you for the nice upload tool.
I was wondering if you are aware of file size limitations. I am successfully uploading small files (1MB is fine). However, when I try to do large files (>10MB) it churns for a long time (as expected) and eventually gives me an “upload successful” message. Yet the file never shows up in the folder. Do you know why this could be happening?
Thanks a lot.
Patrick
Hey Patrick
The docs state that the Flash Player can upload files of up to 100 MB. So you should be okay with the >10MB files. You’ve tested the small files with the same SWF? A common reason for the upload looking ok, but no file shwoing up on the server is due to the folder not having write permission.
Not being a flash guru… is it possible then to use drag and drop and actually drop the file you wish to upload?
Thanks!
Doug
Hey Doug
Unfortunately not. I believe Apollo will give that functionality.
Unfortunately, capturing that drag event isn’t captured by the native Flash plug-in. (At least it’s not been exposed yet.) Several third party tools like Zinc would provide this functionality.
But, I’m with Tink – I can’t wait for Apollo!
Macromedia Apollo (Yes, Macromedia. I haven’t gotten use to Adobe Flash yet.
)
http://labs.adobe.com/wiki/index.php/Apollo
Very usefull. By the way flash 8 has been released. shit stuff u are running here……
you know how to read the date getreal? This pos is over a year old!
[...] ec 2006 api d’upload de fichiers marco wrote this 3:50 pm: A testerEn flashhttp://www.tink.ws/blog/filereference-example En Ajaxxhttp://www.anyexample.com/programming/php/htt [...]
I used the fileReference in one of my latest websites, but you have to try this on MAC OS, it will not work…
Works fine on a Mac, thats what i have.
What problem do you have with it?
Hi Tink,
Thanks for the example, my test worked fine. I am using it to allow my family to upload images, how do you check if the filename already exists? And if so, re-name the file? Is this done in the PHP script?
Thanks
Neil
Yeah you’d have to check that with PHP.
Just wondering if there is a way to return something from the upload call that i could read on the Complete event in flex. Uploading a file and want to tell Flex the path without having to do another service call. please shoot me an email if you know how to do this
why is the source file empty ? just a .txt-file placed!!!!
Try reading the comments!!!!
Hi, thank you very much for the movie, it is just what i was needing, i have look for this for all the web, i am very happy for to find it. Sorry i dont know how and where to put the my server phats for upload and download, can you help me with this?
Thank you very much
Alfonso
Hey Alfonso I’m not entirley sure what your stuck on?
Hi Tink, thanks. Sorry i dont speak english very well. I have my web page http://www.vonschonberg.com and i have a folder “images”. Then i want upload and download the images at this Path: http://www.vonschonberg.com/images/
¿i need to put this path in anywhere of your php file or your fla file for upload or download the images to this folder into my webserver?
my upload and donwnload dont work now
In FileReferenceExemple.fla have put:
//define the path to the server script configured to accept uploads
this._uploadURL_str = “http://www.vonschonberg.com/upload.php”;
…
//open OS window and specify the path to the file to download and the file name that will be displayed
success = this._fileReference.download(“pic2.jpg”, “pic3.jpg”);
I need to change anymore? and in upload.php where put i my folder server for to upload? and where put i my folder server for to downolad?
I have uploaded my .swf page and .swf movies in the root server, and the files from your movie example in the root too
Sorry, i dont know almost to programer i have try all posibilities, i think, but i dont achieve to enreuter the movie example for to work: The Upload say that the file ist me successfully uploaded but i dont find the file uploaded in my server, and the donload say me Upload failed, dont show me any file for to download from my server to my pC
Thank you
Alfonso
I am getting an error trying to upload a file.
I have ensured the uploadedFiles directory has the correct permissions (777)
Basically it is displaying the loading progress bar until it reached 100% then I get the following error:
onHTTPError: site.jpg
////////////////////////////////////////////////////////////////////////////
I have tried with different files and the result is the same.
I am on Windows Vista Ultimate and testing in Firefox 2.0.0.4
Any ideas why I am experiencing this problem?
Could it be anything to do with the fact my server uses the following directory structure?
/httpdocs/uploadedfiles/
All advice much appreciated! I need to get this working so I can then go on to try and create a desktop app that allows users to drag files onto the application to upload them. If I can’t even get this to work I have no hope!!
Amazing, love the idea and the execution. Thanks very much. I am having only one issue.
When the file is uploaded, it is given the permissions 600 (user = rw-, group = —, everyone = —)… Unfortunately the file is owned by Wheel, thus forcing me to chmod and chown each and every time someone uploads a file.
Not sure if this is OS X giving default file permissions, or something on the behalf of flash, but I any advice would be greatly appreciated. If this particular issue is covered in the book, please let me know and I will happily purchase a copy for my self.
Regards,
Mat
my bad, the owner is www, and the group is wheel.
I´ve tried get the path in Flash of file i´ve selected… but i can only have the name with the filereference.name.
Do you know how i can get the path of file i´ve selected in flash (maybe some code in the php part ou something like that???
Thanks and congratulations for the good job!!!
You can’t get the path for security reasons.
Looks great, but, and this seems to be some standard that coders use, why are the most essential pieces of info used to actually make this work so mysterious.
I’m no expert so maybe I’m missing something obvious to some.
Two glaring questions :
Where oh where do I set the path for the folder to upload to? Some php file?
Where oh where do I set the path for the folder to download from? It seems you have it set to download a specific single file?
thanks,
t…
OK, I see where the upload path is set in the upload.php (it’s set to a folder ‘uploadedFiles’) file provided in the source download, and I’ve set the permissions and it works, yes!
How to set the download and read from a folder is still a mystery, for me anyway.
I’m trying but I’m a bit over my head here.
Any help is much appreciated.
t…
You can’t use FileReference to get a list of files in a directory for the download process (or upload for that matter, although as you know you do get to browse on upload).
You could call a PHP script that looks in a folder and returns alist of the files it contains, then display ths is flash, and download the one the user chooses.
function dirList ($directory)
{
// create an array to hold directory list
$results = array();
// create a handler for the directory
$handler = opendir($directory);
// keep going until all files in directory have been read
while ($file = readdir($handler)) {
// if $file isn’t this directory or its parent,
// add it to the results array
if ($file != ‘.’ && $file != ‘..’)
$results[] = $file;
}
// tidy up: close the handler
closedir($handler);
// done!
return $results;
}
Thanks tink, I’ll give it a try and post my results.
Well I’m just lost in space and very frustrated. I gave it my all but I am just not capable of making the flash call the php and return a list. I’m gonna have to try something else, thanks for the effort.
t…
Is it possible to set the target folder for just once when downloading multiple files without letting a user gets prompted for each file he is downloading, assuming that the default filenames are always available?
thanks for the GREAT post! Very useful…
Can we download the source for this yet
Thanks so much and God Bless.
Titus Blair
try reading the previous comments
http://www.friendsofed.com/download.html?isbn=1590595327
Hi Tink!
I just saw your example, but this example only feature single file upload would you give me a code or source for multiple file upload with file reference object, since iam using flash 8 and as 2.0
I just tried your example and it worked all right untill I try to upload a file larger than 8 MB I already tweaked the php.ini to allow larger files but it just doesn’t!
The flash progress and message says the file is uploaded but it isn’t.
Any ideas?
Never minds, sorry to bug you I didn’t realised I had to allow larger POST data in the PHP.INI and it just worked beautifully!
Thanks a million for your script, it does wonders!
hi,
I discover flah,
where can i find the source code of this filereference exemple script ?
thanks
Because In the zip file, there is only a single txt file
best regards
same here, the txt file ironically says:
“Sorry not source until Flash 8 is released.”
pretty cool demo, otherwise . Congratz !:
Hello,
How do I upload a server asp?
Abs,
Rafa
Progres bar dasn’t work, its complite by 2 second but file is stilling upload :/ What is wrong?