I’m going to prefix this tutorial by declaring my love for AJAX to preempt a Flash vs Ajax war. I use AJAX daily, it’s a great tool, the sun shines out it’s arse, etc. But sometimes Flash is just the better tool for the job. I’m going off on a tangent here but many problems with AJAX, e.g. breaks the back button, were the exact same arguments people made about Flash years ago.
ALAX is cool but can you play MP3’s with it? No.
Can you Play Video with AJAX? No.
Upload files with AJAX? No*.
And most importantly can you make a 3D spinning LED thingy in AJAX? No
AJAX file upload is impossible for 99.99% of web users, but Flash file upload is available to 90% of users (the rest are using Gopher on Linux so funk ‘em). As an extra special bonus this example will upload multiple files through Flash, but wait there’s more… it will also include the upload status/progress for each file.

files awaiting upload

uploading with progress

done!
This server side will be Rails but .NET or PHP would work as well. The source for the tutorial is here. Flash files are in the ‘fla’ directory.
As usual start off with a new Rails app
Since we’ll be uploading files we’ll need somewhere to store them preferably in a unique folder so as not to mess anything else up.
Change into the ‘upload’ app directory (not the public/uploads directory) so we can generate models and controllers.
Create a ‘File’ model, ‘File’ is a reserved word for Rails so we’ll call it ‘DataFile’
In the model file (app/model/data_file.rb) we’re going to create a custom save method. It will have three arguments ‘data’ the file data, ‘name’ what to name the file, and ‘directory’ where to put the file.
end
Next create an ‘Upload’ controller
In the controller file (app/controllers/upload_controller.rb) create an index method that takes file information from Flash and passes it to the ‘DataFile’ model. Because there’s no view associated with this controller we add ‘‘ to avoid any errors. We set the upload directory to the ‘uploads’ directory we created earlier "".
end
Almost done, after bashing AJAX earlier it’s time to bash Flash a bit. Flash file upload is broken when used with Rails, from the Bubble Share folk "the Windows version of Flash Player 8 sends a multipart request with content-length set to zero(0), before sending the real request, if the file you are uploading is bigger than 10K". Long story short it no worky with Rails. Big ups to the bubblers they figured out how to fix it, download the fix here and place it in the Rails plug-in directory (vendor/plugins).
That’s it for the Rails side of things (easy peasy lemon squeezy).
Using the source files you can start a webbrick/lighttpd server and test the multipleUpload.fla file in the Flash IDE.
Now on to Flash…
The multipleUpload.fla file has three components on stage, a DataGrid (files_dg), and two Buttons one for browsing the file system (browse_btn), and one for uploading (upload_btn).

The actions for the .fla are pretty short, just creating an instance of a ‘MultipleUpload‘ class (described below) and hooking up the components to it.
import com.vixiom.utils.MultipleUpload
System.security.allowDomain ("*.localhost.com");
var MU:MultipleUpload = new MultipleUpload (this.files_dg, this.browse_btn, this.upload_btn);
Below is the ‘MultipleUpload.as’ file. Here’s a quick run down of what’s going on: a FileReferenceList object is created with a listener that ‘listens’ for various user events dealing with files (onSelect, onCancel, onOpen, onProgress, onComplete, onHTTPError, onIOError, onSecurityError). The major ones are onSelect (when a user selects files with the file browser), onProgress (an interval that runs in reference to a particular file being uploaded), and onComplete (when a file has finished uploading). To show the user the status of our file uploads we’re using the DataGrid’s built in ‘editField‘ method to change what the status cells display.
// delegate
import mx.utils.Delegate;
// ui components
import mx.controls.DataGrid
import mx.controls.Button
// file reference
import flash.net.FileReferenceList;
import flash.net.FileReference;
class com.vixiom.utils.MultipleUpload
{
private var fileRef:FileReferenceList;
private var fileRefListener:Object;
private var list:Array;
private var files_dg:DataGrid;
private var browse_btn:Button;
private var upload_btn:Button;
//////////////////////////////////////////////////////////////////////
//
// Constructor (files_dg, browse_btn, upload_btn)
//
//////////////////////////////////////////////////////////////////////
public function MultipleUpload(fdg:DataGrid, bb:Button, ub:Button)
{
// references for objects on the stage
files_dg = fdg;
browse_btn = bb;
upload_btn = ub;
// file list references & listener
fileRef = new FileReferenceList();
fileRefListener = new Object();
fileRef.addListener(fileRefListener);
// setup
iniUI();
inifileRefListener();
}
//////////////////////////////////////////////////////////////////////
//
// iniUI
//
//////////////////////////////////////////////////////////////////////
private function iniUI()
{
// buttons
browse_btn.onRelease = Delegate.create(this, this.browse);
upload_btn.onRelease = Delegate.create(this, this.upload);
// columns for dataGrid
files_dg.addColumn("name");
files_dg.addColumn("size");
files_dg.addColumn("status");
}
private function browse()
{
trace("// browse");
fileRef.browse();
}
private function upload()
{
trace("// upload");
// upload the files
for(var i:Number = 0; i < list.length; i++) {
var file = list[i];
trace("name: " + file.name);
trace(file.addListener(this));
file.upload("http://0.0.0.0:3000/upload");
}
}
//////////////////////////////////////////////////////////////////////
//
// inifileRefListener
//
//////////////////////////////////////////////////////////////////////
private function inifileRefListener()
{
fileRefListener.onSelect = Delegate.create(this, this.onSelect);
fileRefListener.onCancel = Delegate.create(this, this.onCancel);
fileRefListener.onOpen = Delegate.create(this, this.onOpen);
fileRefListener.onProgress = Delegate.create(this, this.onProgress);
fileRefListener.onComplete = Delegate.create(this, this.onComplete);
fileRefListener.onHTTPError = Delegate.create(this, this.onHTTPError);
fileRefListener.onIOError = Delegate.create(this, this.onIOError);
fileRefListener.onSecurityError = Delegate.create(this, this.onSecurityError);
}
//////////////////////////////////////////////////////////////////////
//
// onSelect
//
//////////////////////////////////////////////////////////////////////
private function onSelect(fileRefList:FileReferenceList)
{
trace("// onSelect");
// list of the file references
list = fileRefList.fileList;
// data provider list so we can customize things
var list_dp = new Array();
// loop over original list, convert bytes to kilobytes
for(var i:Number = 0; i < list.length; i++)
{
list_dp.push({name:list[i].name, size:Math.round(list[i].size / 1000) + " kb", status:"ready for upload"});
}
// display list of files in dataGrid
files_dg.dataProvider = list_dp;
files_dg.spaceColumnsEqually();
}
//////////////////////////////////////////////////////////////////////
//
// onCancel
//
//////////////////////////////////////////////////////////////////////
private function onCancel()
{
trace("// onCancel");
}
//////////////////////////////////////////////////////////////////////
//
// onOpen
//
//////////////////////////////////////////////////////////////////////
private function onOpen(file:FileReference)
{
trace("// onOpenName: " + file.name);
}
//////////////////////////////////////////////////////////////////////
//
// onProgress
//
//////////////////////////////////////////////////////////////////////
private function onProgress(file:FileReference, bytesLoaded:Number, bytesTotal:Number)
{
trace("// onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal);
for(var i:Number = 0; i < list.length; i++)
{
if (list[i].name == file.name) {
var percentDone = Math.round((bytesLoaded / bytesTotal) * 100)
files_dg.editField(i, "status", "uploading: " + percentDone + "%");
}
}
}
//////////////////////////////////////////////////////////////////////
//
// onComplete
//
//////////////////////////////////////////////////////////////////////
private function onComplete(file:FileReference)
{
trace("// onComplete: " + file.name);
for(var i:Number = 0; i < list.length; i++)
{
if (list[i].name == file.name) {
files_dg.editField(i, "status", "complete");
}
}
}
//////////////////////////////////////////////////////////////////////
//
// onHTTPError
//
//////////////////////////////////////////////////////////////////////
private function onHTTPError(file:FileReference, httpError:Number)
{
trace("// onHTTPError: " + file.name + " httpError: " + httpError);
}
//////////////////////////////////////////////////////////////////////
//
// onIOError
//
//////////////////////////////////////////////////////////////////////
private function onIOError(file:FileReference)
{
trace("// onIOError: " + file.name);
}
//////////////////////////////////////////////////////////////////////
//
// onSecurityError
//
//////////////////////////////////////////////////////////////////////
private function onSecurityError(file:FileReference, errorString:String)
{
trace("onSecurityError: " + file.name + " errorString: " + errorString);
}
}
That’s it! I’d love to be proven wrong but that’s impossible to do with AJAX. And if you could do it with AJAX who would want to deal with all the cross browser testing anyways?
*I’ve actually seen a couple of examples of attempts at AJAX file uploading but there’s always some caveat like "only works with FireFox if the user does A, B, and C".
135 Comments
You are a god send! I’ve spent a week battling with Java applets and was getting discouraged after seeing all of the (wonderfully attractive) Flash/Cold Fusion uploaders. Who would have known that I could find a Rails/Flash uploader – exactly what I was looking for.
Anyway – thanks.
I was just looking for a way to upload multiple files using ajax and found:
http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/
Is this missing something that you’re requiring?
What I would like to be able to do is put in a form something like /home/username/pics/*.jpg, and be able to upload multiple files that way.
Gmail has been doing file uploading for some time, where you choose a file to attach to your email, and while you are working on your email, it is uploading the file in the background.
Daniel
The stickman example uses ajax to add addtional file input fields but the actual file uploading isn’t done with ajax (similar to uploading multiple files in BaseCamp).
I think I remember reading that Google uses a hidden iframe and javascript to upload files, which is a work around I used for flash uploading before flash had the FileReference object.
Your /home/username/pics/*.jpg uploader would be pretty sweet, I’d love to be able to just drag a folder of files on to the browser and have the files upload. A buddy of mine developed a system that uploads a zip file of images which then are unzipped and sorted.
Is the Flash for this tutorial Flash 8 or Flash MX (2004) ?
Thanks!!
Can you explain how to deploy this? Sorry, I’m a newbie at both Flash and RoR ^^; . . . .
Hi,
I changed 0.0.0.0:3000/upload to my absolute url: http://www.layoutlemon.com/upload I took out :3000 cuz we’re using Fast-CGI. Is that wrong ? My swf file is here: http://www.layoutlemon.com/swf/multipleUpload.swf
thanks.
d
Hi David,
1. [Is the Flash for this tutorial Flash 8 or Flash MX (2004) ?] Flash 8 was the first version to implement file uploading.
2. [Can you explain how to deploy this?] I wish I had the time but there’s a lot of different variables, including multiple ways of hosting Rails, for deployment. The things to check are; is your ‘uploads’ directory writeable on the production version? Have you tested a simple file upload with a regular RHTML form?
3. [I changed 0.0.0.0:3000/upload to my absolute url...] That’s correct ‘:3000′ is a port number that’s used when testing in development. I tried out your uploader it looks like it’s uploading the file but not saving it so definetly check your file permissions (you’ll have to get your hands dirty with unix commands http://www.rain.org/~mkummel/unix.html) try chmod’ing the uploads directory. > chmod 755 uploads.
BTW the tutorial uses no security checks, in it’s current state it is NOT safe for a public uploader, it could be used for a password protected CMS but I would still check that only certain types of files are being uploaded.
i am a vr new user for flash8 and want to use file upload on my site.
can you tell me how to use this feature??
How to access this from webpage??
where to store files on server??
Very nice tutorial.
To follow up on KreeK’s comment about security; you can add a simple client side security check by passing a FileFilter to the Browse method. For example, fileRef.browse([new FileFilter("Image Files", "*.jpg;*.png;*.gif;*.bmp")]); You can check out a simple example of this here: http://flexonrails.net/imageconverter
Derek
hi
i hv downloaded and run this file working fine but add list viewing single file only i want onemore file view and upload same time plz help me
i want add onemore file file from different folder so please viewing the all browsing file finaly i want uploaad it thanking you
bye saravana
Has anyone got a solution to flash passing the session info for the upload action?
I use a :before_filter login_required and flash doesnt seem to have the same cookie headers.
I think there is a small “Bug”, if you upload bigger files that is time consuming (depends from your bandwidth), so after some time (30secs) you get a “A script in this movie is causing Flash Player to run slowly” alert.
see here:
http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_15512
is there a way to fix this? maybe in “function onProgress” ?
Hi!
One of the sulutions to select at once and upload multiple files or all files within folder is Flash upload control. It works in all browsers and OSs and just needs Flash player on client side.
See example here:
http://www.element-it.com/DEMOMULTIPOW.ASPX
This is very interesting. Thanks. I’m just wondering why you need a database in the example. It doesn’t seem to be used. I would also be interested to know how I can prevent people accessing upload.swf if the are not logged in to my rails application. Any ideas?
“I’m just wondering why you need a database in the example. It doesn’t seem to be used.”
I can’t remember where I found the Rails upload part of it, in this case the file is the ‘Model’ so the ’save’ method is being overwritten to save it in the file system rather than a db. If you wanted to you could move the code that writes the file to the controller.
“I would also be interested to know how I can prevent people accessing upload.swf if the are not logged in to my rails application. Any ideas?”
Yeah that’s a problem (for those that don’t know SWFs can be accessed directly like images), you could use Flash Remoting (http://blog.vixiom.com/2006/08/26/flash-remoting-for-rails-tutorial-data-swings-both-ways/) or XMLsocket (http://www.devarticles.com/c/a/Flash/Working-with-external-data-in-Flash/5/) to check with Rails that the user is logged in. Flash Remoting is a bit more complicated than XMLsocket but has the ability to pass Ruby objects directly into Flash as native ActionScript objects, while XMLsocket brings everything in as a string.
You can still keep the code in the model, just don’t inherit from ActiveRecord. At least that’s what I was thinking
Thanks for your suggestion. I will have a look at it.
I’m coming at this from the Flash side of things so I’m always looking to get better at Ruby/Rails
How would you have a model that didn’t inherit from ActiveRecord? Would it just be a vanilla Ruby class that was in ‘app/models’? (without the ‘< ActiveRecord::Base’)
Exactly. If you don’t inherit from ActiveRecord there’s no need for a database table corresponding to the class.
As you’re not storing anything in the database this would make the most sense imho.
i don’t know if my last comment got submitted so i’ll try once more. sorry if i’m double posting. i was curious if there’s a resolution to flyset’s question (number 15). the only way i’ve been able to alleviate the issue is by completely commenting out the onProgress calls. with the onProgress calls, it seems to slow the script during larger files (20mb or so). any ideas? thoughts?
i am confused, i uploaded your project to server, chmod-ed /uploads directory…
i can select files but when i click UPLOAD button it is trying to connect to 0.0.0.0
i have changed System.security.allowDomain variable in .fla file to my domain with port number and exported as upload.swf to server, replacing original file…
i have changed fileUpload line of /fla/com/vixiom/utils/MultipeUpload.as file to my_domain/upload
still it tries to connect to 0.0.0.0, restarted firefox, emptied cache…
as far as understand, /fla/com/vixiom/utils/MultipeUpload.as is not used, because it is not in public directory, so how is it loaded?
any help?
mirec (Q23) I don’t know if you’ve solved this by now, but MultipleUpload.as is loaded by the import statement in the .fla file (the dots specify the path). As far as setting the domain, those two places (.fla line 3 and .as line 76) should be the only two. I would guess you’re running an un-updated .swf file. Try running it straight out of Flash 8 (ctrl+enter).
Hope that helps! Thanks again, KreeK, for this excellent demo!
Where do I put the path to my upload.php? Im not using Ruby on Rails, So the Flash should know to call my php file…
In the upload function of com.vixiom.utils.MultipleUpload there’s a line (sorry no line numbers)
file.upload(“http://0.0.0.0:3000/uploadâ€);
replace “http://0.0.0.0:3000/upload†with “http://yourdomain/yourupload.phpâ€
The original upload example I modified for rails used PHP it’s in the Flash Documentation (do a search for file.upload).
So, what you’re telling me is that I should trust a totally unknown source with a flash component and allow it full on access to my hard disk? That’s what you’re saying right? Flash with no security model, no signing, no public/private key support? Not gonna happen on this system and I think most people will have the same opinion if they value the contents of their hard drives.
Flash no more or no less safe than you make it. Flash has a security model as of version 8 http://www.adobe.com/devnet/flash/articles/fplayer8_security.html. This example is no more than a glorified file input field and you should obviously check the files with Ruby/PHP/.NET to make sure nothing malicious is being uploaded.
Its very learnful thanks.I have a problem that,there are located multiple image thumbnails in javascript.And when we
click on the thumbnail buton,the large copy of thumbnail want to play in flash.Can it posible with one unique coding
to multiple thumbnails ? Please help me,i am in trouble.
Thank you.
Ajit.
If you’re using Rails and want an image upload and processor I’d suggest looking at “Acts as Attachment” there’s some tutorials on this page http://technoweenie.stikipad.com/plugins/show/Acts+as+Attachment
For help with javascript comunicating with Flash look at http://weblogs.macromedia.com/flashjavascript/ or http://labs.adobe.com/wiki/index.php/Flex-Ajax_Bridge
hope that helps!
This probably qualifies as the longest amount of time ever to reply to a comment (other than never), the answer to flyset’s question (#15), if you’re uploading large files and getting “A script in this movie is causing Flash Player to run slowly”
The answer is here…
http://groups.google.com/group/macromedia.flash.actionscript/browse_thread/thread/108b9acb68910210/5356542492c0456a?lnk=st&q=flash+upload+a+script+is+causing&rnum=1&hl=en#5356542492c0456a
Hey guys, great script!! I’m developing a photo upload program, but am having trouble getting Firefox to upload the photos. IE works great, but one Firefox browser I tested didn’t even open the file window when I hit “Browse”, and another seemed to work fine (show ‘upload 100%’), but the photos weren’t placed anywhere. Is there some settings in Firefox that I need to adjust? Thanks,
Dan
could someone give me a link to a .PHP uploader that i can use for file.upload
thanks
here’s a PHP upload script http://previous.emllabs.com/article.php?articleId=121
Any idea why this crashes and burn when changing
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
to
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
in .htaccess?
The short answer is no, I use mongrel (not lighttpd or mod_fastcgi) for local dev and production sites, I switched after all kinds of fcgi problems.
What is the log saying?
Absolutely nothing, that’s the weird part about it. It’s like the server never gets the request, but it does… because it causes it to freeze without logging/showing anything in the prompt.
Charles is very good at debugging stealth errors http://www.xk72.com/charles/
Also if the fcgi version is on a live site to be sure that you set System.security.allowDomain (“*.localhost.comâ€); in actionscript. Might need a crossDomain.xml file in your rails public directory too (example of one here http://www.adobe.com/crossdomain.xml).
I’m pretty sure it’s a problem of Flash not connecting, but just in case try testing the upload controller with a multi-part HTML form.
hope one of those helps.
Anyone have any examples of integrating this method of upload with a FileColumn field or ImageMagick?
Also, I am not sure the best way of associating the uploaded file with an existing model. My first thought is to pass the model’s id in the query string to the flash script (is this even possible? (never developed with flash before)). The flash script would then pass that id in the url to the upload controller which would handle adding the association. That seems kind of hackish though and not secure.
My other thought is to have flash call a javascript function once the upload is comple, with the name of the uploaded file. That javascript function could then make an ajax call which would handle validation, resize the image, and associate it with the correct model.
Any thoughts / input are much appreciated. Thanks
Hey Matt,
I haven’t tried it with FileColumn, I use Acts as Attachment, I could get files uploaded with AaA but for some reason the resizing that comes with AaA wouldn’t fire (I eventually built my own custom script).
Passing the id in the URL string works the same in Flash as HTML/Javascript, it will be available in Rails as params[:id].
file.upload(”http://0.0.0.0:3000/upload/?id=” + id);
To get the id into Flash you use the ‘FlashVars’ parameter in the SWF file’s Object/Embed tags (the code that places the flash file in an HTML page) like this http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_16417, when you pass a variable into Flash this way it’s available at the _root level of your Flash file (_root.id).
There are many other ways to pass varaibles to/from Flash including XML and Flash Remoting ( http://blog.vixiom.com/2006/08/23/flash-remoting-for-rails-tutorial/ ).
Hope that helps,
Alastair
Thanks Alastair,
I got it working with FileColumn (I am not using AaA) without any difficulty. All you need to do is set your FileColumn field to params[:Filedata] before saving the object.
To handle security I ended up passing a token to the flash file (a SHA1 hash of the users login information). I then pass the token to the Upload controller which handles validating permissions.
I also added functionality to detect when all of the files are done uploading in the ActionScript. When the uploads are complete the AS fires a javascript function which makes an AJAX call to update the users display with the newly uploaded (and resized) images.
If anyone is interested in the code for this shoot me an email, I probably won’t get around to posting it online.
I am still having problems with the “script is running to slowly” errors. I tried creation an onEnterFrame function but it doesn’t appear to be firing. Would anyone mind posting the updated code with this fix in place?
(flash newb)
Also a tip, if your file appears to upload but nothing happens, make sure to monitor your server logs to see if the Upload action was called and if it threw an error or not.
Thanks!
Matt,
I’d love to see the additions you made to the code. I’m looking to exactly the same thing, but I can’t get my rjs to work. I’ve poked around, but can’t find an email address for you either, so I’m posting here in the hopes that you will see this. Please contact me at prog _AT_ keithwoody _DOT_ com.
Thanks in advance.
u madafaka…
I codebreaked this uploader finaly…
I needed to learn Ruby On Rails, but it’s ok..:)
one more thing I know now..
questions :
how to integrate this app with mysql (info of files to be stored in the db )?
I see 001_create_data_files.rb file in db folder, so did you do this allready,
if Yes could you paste sql query for tables, example etc…?
I runned on little problem while uploading big (over 25mb) files.
script makes flash player to run slowly, CPU goes to 100%, and uses all of Virtual Memory..to intensive.. solution for this ?
and BIG THANK YOU for this !
great work, I dl around 20 flash uploaders, and NONE is working.
Only one example using CFM runs perfectly, and this app.
Licence for CFM is 1400$+, so I decided for this one (:
lol
poz
ob1
This uploader appears to upload multiple files at the same time, but according to Flash’s help files and posts I’ve seen elsewhere, files can only be uploaded one at a time. When I do a Test Movie and look at the traces in Output, it indeed appears to be starting additional uploads before completing others.
Is it actually uploading multiple files simultaneously or is this some sort of trick of when certain events fire? Perhaps its attempt to upload everything simultaneously is what is bogging it down when hit with multiple large files? :/
It’s uploading files simultaneously, but you could rework it to have each file wait its turn. The onProgress listener is the cause of the problem, as each file gets its own onProgress listener multiple large files can make it bug out. I’d be interested to know if having files wait their turn fixes that issue, let me know once you build it!
I’ve had success with medium sized files up to 10mb using this fix http://groups.google.com/group/macromedia.flash.actionscript/browse_thread/thread/108b9acb68910210/5356542492c0456a?lnk=st&q=flash+upload+a+script+is+causing&rnum=1&hl=en#5356542492c0456a
Flash also has a built in limit of 100mb.
You can check the file size before upload:
if ((file.size/1024 > maxFileSize) || (isNaN(file.size))) {}
Hi….
Thanks for the code. I too was following the same before. Have you noticed, when you upload multiple Shortcut files, you will get the file size as 0 for everything. Please try to test it. And please let me know the solution.
with best regards
Shibu M
KreeK:[I’ve had success with medium sized files up to 10mb using this fix]
can you please post the piece of code that of this fix?
Kreek, thanks so much for this site.
I’m also having trouble getting the onEnterFrame hack to stop the alert that ’script is making this run slowly….’
I’ve spent a couple hours looking for how to do this, but I can’t figure it out. I also tried the OSflash irc room with no luck. Would you mind emailing me how you got around this problem? thanks a million,
Mike
no matter what i try, i keep getting httpError: 500. on the webrick output, it says POST /upload HTTP/1.1″
nm, fixed it..
I am still not able to get the ’script is making this run slowly….’ message to go away… if anyone finds a working solution please email me the code they used. kaine0[AT]geemail.com (gmail)
Hi
This is just what I need. I have downloaded the files and created a project upload. However, it does not work when i use the url /localhost:3002/upload/index. (data etc is nil). When I use /localhost:3002/ the flash interface is displayed but it does not work . What about the usage of the pasrt “import com.vixiom.utils.MultipleUpload .. i”n your tutorial. I cant find that in any of your files
Need some help, thanks !! (uses rails locally on windows xp)
Hi there,
I’m having some problems here.
I browse for a file and select it. Then…I browse for a second file and select it, but it doesn’t add to the list, it simply replaces the first one.
How can I fix this problem?
Thanks for your help
Antonie,
Right now it selects multiple files at once, but replaces the list if you browse again. ‘onSelect’ is function that fires when you select files you’d need to change it so ‘var list_dp’ wasn’t wiped each time (declare it in the class not the method) then push files to it.
Hans,
com.vixiom.utils.MultipleUpload is in upload/fla/com/vixiom/utils/MultipleUpload if Flash wasn’t finding it you’d get an ActionScript error. Not sure what the problem could be, Do you have Flash Player 8 or greater?
Is there any way to get flash to use the same session when doing file upload. I’ve done pretty much the same thing as you have here but my file upload action gets a different session than the rest of my flash calls to rails. I need to somehow pass the name of the file back to my flash app, but have no way to do this – if i render something in the action it is ignored, if I save it to the session and call another action I get a different session object. any help would be apprechiated.
Hey John,
I didn’t think that would be the case, but you’re right the upload controller has a different session. I thought I could be tricky and use a session from the application controller but that also gave different session objects depending on which controller was calling it.
I’m in the middle of extending this uploaded to a image manager similar to the one for Slide Show Pro (image upload then ability to reorder your images with acts_as_list). The way I’m tracking thins is to pass the ID of the images parent to Flash (using Flash params in it’s object/embed code) then I use Flash Remoting to load any previous images, upload any new ones, and when the upload is finished (which flash knows), I call Flash Remoting again to update my images.
Could that work for you?
thanks,
Alastair
I’m trying to get this to work with PHP but I am having trouble. I have changed the line in the fla to be System.security.allowDomain (”*.mydomain.com”); and I have changed the line in the .as file to be file.upload(”http://www.mydomain.com/upload/upload_process.php”); which is the path to my php file. I continually get an IOError when I run the uploader directly from flash. I know that the php file will process (move it to the desired directory) an uploaded file because I tested the php file from a standard html form. Is there any way to get a clearer understanding of what the general IOError means? Or is it clear to any of you why I am contiuously getting the IOError?
Thanks.
Hey Chris,
An IOError is an Input/Ouput error which most likely means it’s having troubling writing the file. At first I thought it might be a permissions issue but if it works with an HTML form then it’s not that.
Remember that file data from flash comes through as the param ‘Filedata’, where in HTML you can call your file input anything you want, so make sure that’s name you’re using in your process php script.
thanks,
Alastair
PS I’m having my own Flash upload headache right now, seems that with Firefox on Macs flash likes to append port 80 to your upload source (http://mydomain:80/upload/…) which the site I’m working on doesn’t use.
Alastair – thanks for the quick reply. The process file is expecting the param to be ‘Filedata’ – That is how I tested it with my html form as well. Any other thoughts? Should my php file be returning (echoing) any response to the flash file?
@KreeK
Thank you for the comments on preventing the “list_dp” wipe.
I removed the line in the method : “var list_dp = new Array();”
…and defined the variable in the class itself as you said.
Meaning…I added “private var list_dp:Array;” below “private var list:Array;”
For some odd reason it doesn’t work anymore.
Do you have any advice on this?
Thank you very much for your assistance.
All the best,
Antonie
Ok…it works…but it doesn’t seem to put the rows into the grid.
After selecting files, I don’t see them in the flash file, but after uploading, they actually upload. Is there something else I can use other than “push”?
Antonie,
This is an issue with the data grid not updating, which the list_dp is used for (fileReference.list is the list of files to upload). Make sure you have:
files_dg.dataProvider = list_dp;
after each time you push a new item to the list_dp array. Another solution: You don’t have to use a dataProvider to populate a dataGrid you can also use dataGrid.addItem http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00003263.html
hope that helps,
Alastair
Hi, I was trying to save the data of the directory and the filename in a table in the database.
The “upload” database contains a table “data_files” with the fields (id, name, and file)
I got to this and it doesn’t work:
@data_file = DataFile.new
@data_file.save(data, name, directory)
I am having the same problem as rich no matter what i try, i keep getting httpError: 500. on the webrick output, it says POST /upload HTTP/1.1″does anyone know how this was fixed?
thanks for any help
xxxxxxx
For me browse button works – shows files. When I select some files and click Upload – nothing happens.
The following appears in the log:
TypeError (can’t convert nil into String):
/app/models/data_file.rb:5:in `join’
/app/models/data_file.rb:5:in `save’
Looks like – data, file both are blank. could be because of params is empty.
Any suggestions to make this work.
I have flash 9,0,20,8
– sunds2
Hi,
I am unable to figure out how the flash code will work with the rails application and is there a way by which we dont have to hard code the url used in the .fla and .as files?
There are a number of ways of passing a variable (in this case a url string), these links show how with a query string (http://www.permadi.com/tutorial/flashQueryString/) or with FlashVars (http://www.permadi.com/tutorial/flashVars/). The variables will be available at the root of the main movie, so if you pass a variable called ‘url_string’ it will be accessible as ‘_root.url_string’
I get the same error as comment 72. File upload works out of Flash. I changed the domain to my ip address in the fla and the upload to my address as well.
What I also did is I created an uploads folder in the rails root directory, because the rails app is trying to save there and not in public/uploads (before that I was getting 500 errors with uploading from Flash).
Now uploading from Flash works fine, but if I try in FF or IE nothing happens and I see in the webrick log that a file called crossdomain.xml is needed but not found.
Anybody an idea on this? Thx
Hey guys I was able to fix the “A script in this movie is causing Flash Player to run slowly” problem by using an onEnterFrame event and have posted the updated source code on my blog at http://rockstardeveloper.com/articles/2007/04/22/flash-script-running-too-slowly
Hi,
I have a security problem as well, but I see in firebug the movie tries to load the crossdomain.xml from http://0.0.0.0:3000/crossdomain.xml even if my host is my life system. Where can I set this ip?
@Kai
Put the crossdomain.xml file in the root of your rails app, this is Adobe’s crossdomain file http://www.adobe.com/crossdomain.xml. In your case have the domains be ‘0.0.0.0:3000′ (which is the same as localhost:3000) and then also the domain for your live site.
You usually only have rails running at 0.0.0.0:3000 for development, when you deploy an app to a production site any calls to files would be from the domain.
Great work!
I’m trying to figure out how to integrate the flash uploader w/ a PHP script and I’m having some major headaches. It might just be my lack of knowledge on how this works. I know nothing about Ruby, hence why I’m trying w/ PHP. The problem I keep running into or can’t seem to figure out is what does the flash script pass variable-wise? I get the idea of linking to the PHP script so that it can call on that to do the actual uploading, but what variable goes into the PHP script as the file data so it knows what to upload?
I apologize if these are newb-ish question, but I’m stuck and would love to use this uploader!
Hey Tim,
The variable coming across will be called ‘$_FILES['Filedata']‘ there’s an example PHP script on Adobe’s site http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001054.html
did anybody figured how this works? i am getting interface loaded ok and able to browse and add files ( it replaces the prev one so seems to be one file at a time but when clicking on upload button nothing happens. how do you debug this thing? i am using ie
Hello !
Just a came to think of this, lets say your solution will be i an application witch requires login (thus generating a session id), will this session id be carried thru the flash upload,
in order to separate several users logged in at the same time, so that they upload to their respective upload directories (named via their separate session id)?
Sinc Kalle Johansson
@Kalle
The uploader will have a seperate session, however you can pass a user_id to flash which can then be sent along with the upload params to make sure the uploaded files are saved with the correct user… just append the user_id to the upload url
file.upload(”http://0.0.0.0:3000/upload/123″);
I tried to used this flash uploader with Java (jakarta.apache.org/commons/fileupload). But gives an error when using with this Flash multi file uploader..
“Processing of multipart/form-data request failed. Stream ended unexpectedly”
Can anybody help me.. Has anybody tried this with java/j2ee ?
I just ‘fixed’ the Flash 8 issue with some carefully crafted Apache2 rewrite rules, if anyone is curious.
http://edseek.com/archives/2007/07/15/flash-upload-progress-for-rails-with-fancyupload-for-mootools/
Enjoy!
Hey Jason nice work
Hi,
I start learning Ruby on rail. I got this error while I try this exercise.
Help!
=====================================
TypeError in UploadController#index
can’t convert nil into String
RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace
#{RAILS_ROOT}/app/models/data_file.rb:5:in `join’
#{RAILS_ROOT}/app/models/data_file.rb:5:in `save’
#{RAILS_ROOT}/app/controllers/upload_controller.rb:10:in `index’
Request
Parameters: None
Show session dump
—
flash: !map:ActionController::Flash::FlashHash {}
Response
Headers: {”cookie”=>[], “Cache-Control”=>”no-cache”}
=====================================================
Hi I’ve try it in mi personal computer and it works excelente but when i run it on my notebook every time I click on the uploa button it close my browser (I’ve tried reinstalling flash, shockwave, installing firefox, safari). This error happens with all the browser. I suposse is an dll problem but i have no idea where to start, any suggestions????
Thank in advance
Excellent guide, thank you very much. How would you recommend extending this to support queued upload (ie, one file at a time)?
I am not able to configure the application at my PC. Can please explain the steps to get the application up and running. Please help as i need to get it running
.
Regards,
Amit
Hi Amit,
The solution is to buy a mac
Could you provide more information on what is not working?
I’m using this to upload files to a Java servlet, which uses Apache commons FileUpload package. I observe that Flash Player 9 works just fine but version 8 has a problem. Uploads would reach 100% but never change into “completed” state. I’m not sure what the cause is. Anybody has any suggestion?
I have the file upload dialog coming up. But clicking on Upload button nothing happens. Nothing is getting logged into either Mongrel or Webrick.
I saw someone suggesting to update url in .fla and .as files. I Changed it in .as file to http://localhost:3002/ but .fla to me appears to be a binary file.
Any assistance would be appreciated.
Flash files must be compiled through the Flash IDE to implement any changes to an associated .as file (I’m guessing you don’t have the IDE as the .fla is a binary file for you).
Sounds greek to this newbie. I know nothing about flash except the fact I was impressed that it can be used in my rails project to upload files to my site. I
Have I downloaded this rails plugin correctly? I downloaded multiFlashRailsFileUpload.zip and unzipped to a folder and installed this as a plugin.
Should I try again?
Where do I Get the Flash IDE? I have Aptana IDE – can I use that. From the Flash IDE I should compile .as file (after making changes) and create .fla and .swf?
To get a 30 day trial of Flash go to http://www.adobe.com/go/tryflash , you could also use Flex but this example uses ActionScript 2.0 (AS2) and you would have to convert it to AS3 for Flex.
I have a Flex/AIR example which uses Merb (similar to Rails) here http://blog.vixiom.com/2007/06/29/merb-on-air-drag-and-drop-multiple-file-upload/
Unlike Flash you can get Flex for Free http://www.flex.org/ , but Flex Builder (the Flex IDE) makes working with Flex much easier.
I don’t want to discourage you but if you’ve never used Flash/Flex it can be a pretty steep learning curve. However, if you know JavaScript then you should be able to pick up ActionScript pretty quickly.
Thanks Alastair.
Hey,
I put it up, replaced 0.0.0.0 with the absolute directory in which i want it to upload
i press upload and it goes up to 100%
but the file isn’t in the directory i typed in, in fact it’s not anywhere on the site.
Sorry i forgot to mention.
your screen shot says “complete” mine just says “100%” and stops…
HOW CAN I MAKE IT TO UPLOAD ONE FILE AT A TIME. i get SIMULTANEOSLY UPLOADS . i need them to be in order by name or so..
is there a way ?
Hi, I have the same problem as stan, when selecting files they are replacing each other rather than getting added to the file list with Flash Player 9,0,47,0
Any thoughts?
Cheers, Neil
Sorry didn’t read the comments – answered by KreeK at comment 58 (http://blog.vixiom.com/2006/09/08/multiple-file-upload-with-flash-and-ruby-on-rails/#comment-19644)
Neil
@Chris re: comment #62 (and others),
The IO error 403 seems to be related to mod_security issues with apache servers which blocks flash headers.
A work around is to add the following to the .htaccess file in your root.
SecFilterEngine Off
SecFilterScanPOST Off
No idea how that effects security though?
I am trying to create a remove function so a user can remove a select files, but I can not get it to work.
function removeClick(){
var numItems:Number = files_gd.length;
for(var i=0; i
Quote comment 84:
The uploader will have a seperate session, however you can pass a user_id to flash which can then be sent along with the upload params to make sure the uploaded files are saved with the correct user… just append the user_id to the upload url
file.upload(”http://0.0.0.0:3000/upload/123″);
**************
How can I go about doing this? I thought that any change to the url in the actionscript would have to be compiled into the flash binary file? Could you explain how I can go about dynamically passing a user_id to the flash uploader so that I can stick a user_id in the DB when I save the uploaded files?
Thanks
arfon
@Arfon you’re right that an actionscript change has to be compiled, you’ll need the Flash IDE to make this change. If you don’t have it Adobe has a 30 day trial version.
To get the user id into Flash you pass it in the embed code (the code that places flash on the html page) the best way to do this is with SWFObject (http://blog.deconcept.com/swfobject/) you add a line like so.addVariable(”variableName”, “variableValue”);
Then ‘variableName’ will be available at the root of the Flash file.
Thanks. That’s really helpful. So just to clarify, once I’ve passed the variables to the flash in the embed code, do I have to access them in in the original actionscript file, then re-complile it with the changes that I have written?
I basically want to build the url that flash uses like this:
file.upload(”http://0.0.0.0:3000/upload?userid=123&var2=1″);
How do I build the variables into the url? i.e. once they are available at the root of the flash file how do I access them? (I’m a complete neewbie to flash/as)
Thanks for all your help
The original AS file (that you download from this page) doesn’t have these variables set up yet. But when you are editing the file (to be recompiled by Flash) the variables will be available as _root.variableName.
ActionScript is like JavaScript so to build the upload url you would be;
file.upload(”http://0.0.0.0:3000/upload?userid=” + _root.userid + “&var2=” + _root.var2);
When using Flash you can test your file without putting it on the server (files will upload), however with testing you won’t have those variables set up yet because they come from SWFObject’s embed code, so you’ll have to set temp vars, just put _root.varaibleName = variableValue; in MultipleUpload.as’s constructor (of course remove it for the final version).
Alastair you’re a star. Thanks so much, it’s all working perfectly now.
Can you please correct your bullshit to correctly capitalise Ajax? It’s not an Acronym young Luke. Second, Flash is NOT better then Ajax because Flash does not have Usability in mind, what happens if I don’t have JavaScript enabled? It works; but with no Flash, your flaky bullshit fails, FAILS! Anyways, I think people should have better things to do then listen to somebody who can’t even correctly capitalise Ajax
.
Can you publish a merb version of the same tutorial? Thx.
@EnvyGeeks you have much to learn my young Padawan A.J.A.X stands for Asynchronous JavaScript and XML. That said it now has become a noun so yes you can use it U&LC and your ignorance will be excused (U&LC stands for ‘upper and lowercase’ if you don’t know).
AJAX works if you don’t have JS?, yes simple stuff works but complex AJAX won’t. Those in the know use SWFObject with Flash which lets you replace Flash seamlessly if no player is found.
BTW (that’s ‘By The Way’) javascript is turned on in 94% of browsers and Flash 8 (used in this example) has 98.4% penetration so even if AJAX could do multiple file upload (which it can’t) Flash would still be the better choice.
I think people should have better things to do then listen to somebody with two assholes cause I just tore through your argument and gave you a new one
@mike for merb it’s pretty much the same as this http://blog.vixiom.com/2007/06/29/merb-on-air-drag-and-drop-multiple-file-upload/ but sub Flex/AIR for this Flash.
Consider Merb if you need authentication support for your uploads . . .
http://merb.devjavu.com/attachment/ticket/82/fixation_exclusion_white_list.diff
So there is no way of getting this to work in a Rails setting in which authentication(Basic Authentication) is required?
Hi there!
Could one of you guys tell me how to use this? The zip contains 48 folders and 68 files???
I’m ONLY interessed in integrating the upload functionality into my asp.net 2.0 web site…
/Pablo
We have a weird issue where we get a 406 error from our uploads. Tons of forums talk about this with PHP blaming it on mod_security. That does not seem to be the issue with rails though, obviously (though we made the fixes anyways).
Here is where it gets even cooler – we do not get 406s on Safari, but we do get them from Firefox and IE.
hello,
First of all, thank you for putting up the tutorial. It is great.
I think i am getting very close but upload doesn’t work for me. I have downloaded “Instant Rails”, set it up, ran the scripts & created “upload” project as instructed, turned the debugger on, ran the movie & .rs file in Flash, browsed for a file. But, when i click on ‘upload’, it gives error. Console output is:
// onOpenName: user_flow.txt
// onIOError: user_flow.txt
In the debugger, I can see the flow comes to the line:
file.upload(”http://120.0.0.1:3000/upload”);
The flow went to function onOpenName, onIOError as indicated by the console output. After the IOError, nothing happens. I put these two line in the $RAILS_DIR\rail_apps\upload\public\.htaccess file, but it didn’t make a difference.
SecFilterEngine Off
SecFilterScanPOST Off
Here are some further info:
Instant Rails version: v2.0
File to be uploaded: c:/…/user_flow.txt (a dir outside of Flash workspace)
If I leave the IP to be 0.0.0.0, it doesn’t make a difference either.
Can someone help?? Thanks in advance!
-Ivy
// onOpenName: user_flow.txt
// onIOError: user_flow.txt
SecFilterEngine Off
SecFilterScanPOST Off
I have been using the FlashFixes plugin to fix the Flash 8 problems but have found some issues. It causes my Mongrel to hang on certain requests from Safari/Mac, lately also through Picnik integration. It causes the Mongrel process to cap to 100% CPU, needing a restart. Taking it out seems to solve the issue. Has anyone seen this?
Quick update, I think the FlashFixes does not have patch for a DOS issue that has been applied to CGI.rb. Since it redefines a method in CGI.rb, we lose any upgrades (for example, security upgrades) to that method that have occurred. Here is info on the DOS patch http://www.ruby-lang.org/en/news/2006/12/04/another-dos-vulnerability-in-cgi-library. Flashfixes is missing the c.empty? check that CGI.rb has been updated with along with some other things. Given this, I’m not sure if it is such a good idea to redefine this method in a plugin unless updates are kept current…
My company just released a flash multiple-file upload applet called Multi Bit Shift, available at multibitshift.com. We make a LGPL version that is pretty similar to this software available as a free download. In addition, we also have a Rails Plugin available that makes it really easy to integrate into an existing form with a very railsy helper, multi_bit_shift_field, which acts pretty much exactly how you would expect it to. All the text in the applet is customizable, as our the colors, with CSS. We even provide a form on the website that the CSS can be easily compiled to flash with so you don’t need to deal with flex at all. In addition, we also offer a commercial version that’s designed with images in mind that will let your users see what files are on the server.
I hope this isn’t considered spam, the plugin and the basic version are LGPL after all.
If you want to use this with web2py the web2py code equivalent to the ruby code above is:
db.define_table(’DataFile’,SQLField(’Filename’),SQLField(’Filedata’,'upload’))
def index(): return SQLFORM(db.DataFile).accepts(request.vars,formname=None)
The web2py code provides additional security. The ruby code above is vulnerable to directory traversal attacks.
Hi,
that link Matt (comment 76) posted was broken. Anyone else fixed the Actionscript running slowly popup.
many many thanks
jJ
While searching to multiple file upload tutorial , I have found the blog on google. Reading here it seems its better I try to do it in Ajax . I m completely new to Ajax. Usually I do programming for windows . From where I should start learning Ajax? I mean any tutorials u can recommend
So looks like everyone has to recompile the flash themselves so that it uploads to the correct location?
Why on earth didn’t you just make the upload-destination a parameter to the flash file, so we could just use the demo one?
I’ve put a wildcard crossdomain.xml on my local site, but still get nothign besides a message from firefox that it’s “Transferring data from 0.0.0.0″. Running on port 3000 as expected… any ideas?
The solution for “A script in this movie is causing Flash Player to run slowly” alert is the following:
1) Open MultipleUpload.as
2) Edit upload function adding this line:
private function upload()
{
trace(”// upload”);
// This will prevent Flash from reporting a slow-running script
startSomeNonsense();
….
}
3) Add this function somewhere
function startSomeNonsense(){
var count:Number = 0;
_root.onEnterFrame = function(){
count += 1;
}
}
4) Publish the .fla file with flash and use your new MultipleUpload.swf copy.
Thats it.
Did anyone ever get a php version of this working… a link or a rough guide would be ideal
I use your Rails App as a server and my own Flex Uploader with the URLRequest-Class.
It should work but when I send a file to the server I get a:
Processing UploadController#index (for 127.0.0.1 at 2008-12-29 15:44:22) [POST]
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%0ASGFzaHsABjoKQHVzZWR7AA%3D%3D–c6aef7c6c66b984c2b6f90a511aab81987f03184
Parameters: {”Filename”=>”me.jpg”, “action”=>”index”, “Upload”=>”Submit Query”, “controller”=>”upload”, “file”=>#}
NoMethodError (You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.read):
Any idea what the nil object can be? THX
Ok first off I love this Tutorial and setup!! So thank you
I am using it via PHP so anyone who needs help with it you just have to change your upload.php file to the following:
This will create a directory for you and give it read/write privileges for any novices. Also, for the novices, your file first transfers to a temp folder on the SERVER, once it is verified it will get moved to the directory you chose, in this case, “gallery”.
For anyone who wants to REMOVE a file that has been added to the list. This one was tough.
Copy the Browse button from the multipleUpload.fla file and paste it so you have two of them. Change the name to “Remove” (or whatever you want it to be) and make sure you change the instance name to remove_btn.
Now onto the MultipleUpload.as file…
Add a new private variable with the other ones
private var remove_btn:Button;
Add rb:Button to the following:
public function MultipleUpload(fdg:DataGrid, bb:Button, ub:Button, rb:Button)
Set it equal like the rest:
remove_btn = rb;
Inside the iniUI function add in:
remove_btn.onRelease = Delegate.create(this, this.remove);
Now create a brand new function exactly like the following:
private function remove()
{
trace(”// remove”);
var t:Number = files_dg.selectedIndex;
list.splice(t, 1);
files_dg.dataProvider.removeItemAt(files_dg.selectedIndex);
}
Since the File list is an Array we can just alter the array.
We first grab our index that was selected by the user and set that number to t.
We then splice it (or remove it from the array)
We finally delete it off of the visual list.
Not sure if anyone else made something like this but I thought I would share…I will check back if anyone has questions…
You really suck!! AJAX can do that and more!!!
Hello im hiro nakamura. may somebody guide me how to put the file and code “multiFlashRailsFileUpload”. I really blur about it, please,.. very thanks for anybody who would be help me.
I need the root information where and hoe to put the directory / folder for this multiFlashRailsFileUpload file.
Great thanks for u all
Is the “integration” of this script only with PHP, FLASH and ActionScript difficult?
I mean, withouth rails?
Regards
hi,
Works great locally but on my server there’s no feed back when uploading. Looks like it never starts. But the file is uploaded.
Hi,
Great info. Been using this for over a year.
Got a new server this week and now onProgress and onComplete is no longer invoked/fired.
Anyone that can give me a clue what this can be?
Best regards,
M
Anyone using Amazon S3 who is interested in uploading multiple files directly to S3 without hitting the server might be interested in my posts here:
http://www.railstoolkit.com/posts/fancyupload-amazon-s3-uploader-with-paperclip
http://www.railstoolkit.com/posts/uploading-files-directly-to-amazon-s3-using-fancyupload
Thank you for posting this tutorial. Can you email me the plugin fix from bubbleshare? According to their site, they are no longer operating.
Thanks,
Frank
Hi Alastair,
I am trying to upload a zip file to rails from flash using the fzip library for flash. I am having a difficult time getting this to work, getting errors from flash that I cannot figure out, and the logs from ruby dont really tell me much in the way of whats going wrong. I saw that one of your comments, you mention that a buddy of yours managed to transfer zip files from flash to rails and I was wondering if you knew anything about how this could be done. I have tried everything within my knowledge of flash and rails to try and get past this but am having a real crazy time with it. I have tried to find a contact email to get in touch with you about this, but couldnt find any and I dont have a linkedIn account.
Great post and blog by the way, found some useful tips and resources in here.
Regards
hi, very nice scrpt, have a ask.
how can i implete this in my flash without use the class. i mean how to change to as2 script without using the class.
thanks
i have tryed like this, but not works
stop();
System.security.allowDomain (”*”);
import flash.net.FileReferenceList;
import flash.net.FileReference;
var fileRef:FileReferenceList;
var fileRefListener:Object;
var list:Array;
var listenerObject:Object = new Object();
var item:Number;
var totalByte:Number = 0;
var percentBar:Number=0;
var currentFile:Number = 0;
var fileComplete:String=” 0 files”;
var mPhp:String;
var ei1:Boolean;
var listFiles:Array;
var allTypes:Array = new Array();
var imageTypes:Object = new Object();
var maxFileSize:Number = 0;
var fileTypeDes : String = “All files”;
var fileTypes : String = “*.*”
listFiles = [];
imageTypes.description = fileTypeDes;
imageTypes.extension = fileTypes;
allTypes.push(imageTypes);
fileRef = new FileReferenceList();
fileRefListener = new Object();
fileRef.addListener(fileRefListener);
upload_listener.onSelect = function(fileRefList:FileReferenceList) {
for (var i: Number=0; i<fileRefList.fileList.length; i++){
var file : FileReference = fileRefList.fileList[i];
}
copyArr(list, fileRefList.fileList);
var list_dp = new Array();
for (var i:Number = 0; i<list.length; i++) {
list_dp.push({name:list[i].name, size:Math.round(list[i].size/1000)+" kb", status:"ready for upload"});
}
}
// onOpen
upload_listener.onOpen= function(file:FileReference) {
}
// onProgress
upload_listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number) {
}
// onComplete
upload_listener.onComplete= function(file:FileReference) {
if (currentFile<list.length) {
listFiles.push(file.name);
currentFile++;
upload();
} else {
currentFile =0;
}
for (var i:Number = 0; i<list.length; i++) {
if (list[i].name == file.name) {
fStatus.text += "complete";
}
}
}
//onHTTPError
upload_listener.onHTTPError= function(file:FileReference, httpError:Number) {
}
upload_listener.onIOError= function(file:FileReference) {
}
// onSecurityError
upload_listener.onSecurityError= function(file:FileReference, errorString:String) {
}
function copyArr(tar,src: Array){
for (var i: Number =0; i<src.length; i++){
tar.push(src[i]);
}
}
function upload() {
var file = list[currentFile];
file.upload("uploadfiles.php");
}
function browse() {
currentFile = 0;
percentBar = 0;
totalByte = 0;
fileRef.browse(allTypes);
}
bt1.onRelease = function(){
browse();
}
bt2.onRelease = function(){
upload()
}
Hi!
It’s very good this tutorial but the link to the plug-in that solve the Rails problem is broken (to place in directory: vendor/plugins). Do you know where i can find it?
Thx to everyone.
15 Trackbacks
[...] Un “applet” de Flash para subir archivos a tu aplicación RoR. [...]
[...] The first one is doing Multiple File Uploading with Flash and Ruby on Rails. This one has a nice to use interface and seems workable if you dont mind using flash in your project. [...]
[...] Tutorial Multiple File Upload with Flash and Ruby on Rails [...]
[...] When uploading a file through Flash every file comes through as with it’s .content_type as ‘application/octet-stream’ so you can’t check it using traditional methods*. [...]
[...] Vixiom Axioms » Multiple File Upload with Flash and Ruby on Rails [...]
[...] Opencard Me and Welby went to the Academie voor popcultuur today to do a bit of card-testing under the students. We didn’t got as many people as we wanted but we did found out some interesting results. I think we’ll be using some or all of them as far as possible of course. Upload system Today’s has also been about finding a way to upload files to a website because its one of the items were going to use in the website for the Academie voor popcultuur. I found this very usefull here is the link. [...]
[...] Vixiom Axioms » Multiple File Upload with Flash and Ruby on Rails Useful tutorial for beginning to get flash and ruby speaking with each other. (tags: flash rails ruby coding programming tutorial) [...]
[...] Vixiom Axioms » Multiple File Upload with Flash and Ruby on Rails 플래시와 ë ˆì¼ì¦ˆë¥¼ ì´ìš©í•œ íŒŒì¼ ì—…ë¡œë“œ (tags: flash flex í”Œë ‰ìŠ¤ file upload) [...]
[...] 利用Googleæœç´¢ï¼Œå‘çŽ°æ— æ•°çš„äººä¹Ÿåœ¨è¯¢é—®åŒæ ·çš„é—®é¢˜ã€‚åŽæ¥åœ¨è¿™ç¯‡ä»‹ç»ç”¨Flex实现的批é‡ä¸Šä¼ çš„æ–‡ç« åŽçš„评论里é¢ï¼Œæ‰¾åˆ°äº†ä¸€ä¸ªå«åšâ€œTimothee Groleauâ€çš„哥们的“自问自ç”â€ï¼Œç»ˆäºŽè§£å¼€äº†è¿·å›¢ï¼šFlashPlayer在触å‘å¹¶æ‰§è¡Œç”¨æˆ·å®šä¹‰çš„è„šæœ¬ï¼ˆå°±æ˜¯ä½ ç¼–å†™çš„ActionScript)时,会é‡ç½®â€œè„šæœ¬è¶…æ—¶å€¼â€ï¼ˆä¸Šæ–‡æåˆ°çš„15ç§’ï¼‰ã€‚è¿™æ ·ï¼Œæˆ‘ä»¬å¯åœ¨æŸä¸€ä¸ªâ€œé©¬ç”²MovieClipâ€ä¸Šç»‘定一个onEnterFrameäº‹ä»¶ï¼Œè®©å®ƒä¸æ–地(é€å¸§ï¼‰æ‰§è¡Œã€‚最简å•çš„åšæ³•就是: [...]
[...] Scope Chain and Memory waste in Flash MX Uncategorized Code Examples & Tips Alastair Dawson :: Multiple File Upload with Flash and Ruby on Rails Andrew Trice :: Benefits of defining a custom event type for data binding :: E.g. [...]
[...] Scope Chain and Memory waste in Flash MX Uncategorized Code Examples & Tips Alastair Dawson :: Multiple File Upload with Flash and Ruby on Rails Andrew Trice :: Benefits of defining a custom event type for data binding :: E.g. [...]
[...] Alastair Dawson :: Multiple File Upload with Flash and Ruby on Rails [...]
[...] Scope Chain and Memory waste in Flash MX Uncategorized Code Examples & Tips Alastair Dawson :: Multiple File Upload with Flash and Ruby on Rails Andrew Trice :: Benefits of defining a custom event type for data binding :: E.g. [...]
[...] reading Multiple File Upload with Flash and Ruby on Rails and Merb on AIR – Drag and Drop Multiple File Upload I decided to create my own version of [...]
[...] folgende beim googlen gefunden es funktioniert auch. LINK wie kann ich als reine as code, ohne laden der klasse [...]