Multiple File Upload with Flash and Ruby on Rails
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 :P
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".




Like this post? subscribe to the feed.
[…] Un “applet” de Flash para subir archivos a tu aplicación RoR. […]
Pingback by Mi viaje en tren » Blog Archive » Avistamientos #5 — September 15, 2006 @ 4:48 pm
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.
Comment by Alex — September 18, 2006 @ 5:00 pm
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
Comment by Daniel S. — September 22, 2006 @ 12:24 pm
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.
Comment by KreeK — September 22, 2006 @ 12:45 pm
Is the Flash for this tutorial Flash 8 or Flash MX (2004) ?
Thanks!!
Comment by David Beckwith — September 23, 2006 @ 9:03 pm
Can you explain how to deploy this? Sorry, I’m a newbie at both Flash and RoR ^^; . . . .
Comment by David Beckwith — September 23, 2006 @ 10:09 pm
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 :)
Comment by David Beckwith — September 23, 2006 @ 11:58 pm
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.
Comment by KreeK — September 24, 2006 @ 9:52 am
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??
Comment by Tarpan — September 29, 2006 @ 6:53 am
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
Comment by Derek Wischusen — September 29, 2006 @ 7:24 pm
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
Comment by saravana — October 3, 2006 @ 3:06 am
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
Comment by saravana — October 3, 2006 @ 3:12 am
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.
Comment by Rex — October 4, 2006 @ 3:46 am
[…] 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. […]
Pingback by Multiple File Uploads with Rails and Progress Bars — October 8, 2006 @ 4:18 pm
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” ?
Comment by flyset — October 9, 2006 @ 3:12 am
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
Comment by Gregory — October 16, 2006 @ 2:25 am
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?
Comment by Mischa — October 30, 2006 @ 8:44 am
“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.
Comment by KreeK — October 30, 2006 @ 10:15 am
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.
Comment by Mischa — October 30, 2006 @ 12:37 pm
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’)
Comment by KreeK — October 30, 2006 @ 12:54 pm
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.
Comment by Mischa — October 30, 2006 @ 1:27 pm
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?
Comment by anthony — November 12, 2006 @ 5:24 pm
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?
Comment by mirec — November 16, 2006 @ 3:45 am
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!
Comment by A.Boltz — November 19, 2006 @ 7:46 pm
[…] Tutorial Multiple File Upload with Flash and Ruby on Rails […]
Pingback by .bootstrap » Beautiful and Efficient File Upload using Flash and Ruby on Rails — November 20, 2006 @ 10:59 am
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…
Comment by alon — November 30, 2006 @ 10:04 am
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).
Comment by KreeK — November 30, 2006 @ 8:53 pm
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.
Comment by Greekkit — December 1, 2006 @ 12:13 am
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.
Comment by KreeK — December 1, 2006 @ 12:41 am
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.
Comment by Ajit Chougule — December 6, 2006 @ 11:03 pm
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!
Comment by KreeK — December 7, 2006 @ 7:20 am
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
Comment by KreeK — December 17, 2006 @ 9:28 pm
[…] 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*. […]
Pingback by Vixiom Axioms » Flash image upload security with Ruby on Rails — December 18, 2006 @ 7:29 am
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
Comment by danny — December 20, 2006 @ 8:29 am
could someone give me a link to a .PHP uploader that i can use for file.upload
thanks
Comment by jun — December 20, 2006 @ 3:19 pm
here’s a PHP upload script http://previous.emllabs.com/article.php?articleId=121
Comment by KreeK — December 20, 2006 @ 3:31 pm
Any idea why this crashes and burn when changing
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
to
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
in .htaccess?
Comment by Heist — December 21, 2006 @ 12:03 pm
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?
Comment by KreeK — December 21, 2006 @ 12:46 pm
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.
Comment by Heist — December 21, 2006 @ 1:04 pm
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.
Comment by KreeK — December 21, 2006 @ 1:25 pm
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
Comment by Matt — December 31, 2006 @ 5:44 pm
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
Comment by KreeK — January 1, 2007 @ 6:22 pm
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.
Comment by Matt Kull — January 1, 2007 @ 10:56 pm
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!
Comment by Matt — January 4, 2007 @ 9:51 pm
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.
Comment by Keith — January 9, 2007 @ 4:37 pm
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
Comment by ob1y2k — January 16, 2007 @ 7:05 am
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? :/
Comment by Mike — January 18, 2007 @ 2:07 pm
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))) {}
Comment by KreeK — January 18, 2007 @ 3:14 pm
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
Comment by Shibu — January 24, 2007 @ 12:02 am
[…] Vixiom Axioms » Multiple File Upload with Flash and Ruby on Rails […]
Pingback by mutterings » Blog Archive » Multiple File Upload with Flash and Ruby on Rails — January 26, 2007 @ 2:12 am
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?
Comment by redron — January 29, 2007 @ 8:10 am
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
Comment by Mike Michelson — February 3, 2007 @ 11:48 pm
no matter what i try, i keep getting httpError: 500. on the webrick output, it says POST /upload HTTP/1.1″
Comment by rich — February 9, 2007 @ 12:05 pm
nm, fixed it..
Comment by rich — February 9, 2007 @ 2:17 pm
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)
Comment by Matt Kull — February 12, 2007 @ 10:07 pm
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)
Comment by Hans — February 15, 2007 @ 4:43 am
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
Comment by Antonie Potgieter — February 15, 2007 @ 8:26 pm
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.
Comment by KreeK — February 15, 2007 @ 8:52 pm
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?
Comment by KreeK — February 15, 2007 @ 9:00 pm
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.
Comment by John — February 16, 2007 @ 8:15 am
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
Comment by KreeK — February 16, 2007 @ 11:27 am
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.
Comment by Chris — February 22, 2007 @ 1:39 pm
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.
Comment by KreeK — February 22, 2007 @ 1:58 pm
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?
Comment by Chris — February 22, 2007 @ 2:17 pm
@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
Comment by Antonie Potgieter — February 23, 2007 @ 10:48 pm
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”?
Comment by Antonie Potgieter — February 23, 2007 @ 10:54 pm
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
Comment by KreeK — February 24, 2007 @ 1:08 am
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)
Comment by Japo — February 26, 2007 @ 11:52 pm
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
Comment by rafael — March 4, 2007 @ 12:33 am
xxxxxxx
Comment by Ganesh Iyer — March 22, 2007 @ 6:59 am
[…] 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. […]
Pingback by Mike’s blog » Blog Archive » Opencard testing and Upload systems — March 27, 2007 @ 10:38 am
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
Comment by sunds2 — April 8, 2007 @ 7:47 pm
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?
Comment by Neha — April 20, 2007 @ 4:35 am
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’
Comment by KreeK — April 20, 2007 @ 10:32 am
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
Comment by sashthebash — April 21, 2007 @ 11:12 am
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
Comment by Matt Kull — April 22, 2007 @ 12:59 pm
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?
Comment by Kai Rautenberg — May 5, 2007 @ 1:55 pm
@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.
Comment by KreeK — May 6, 2007 @ 11:49 am
Great work!
Comment by Helmut — May 30, 2007 @ 10:12 am
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!
Comment by Tim — June 4, 2007 @ 7:19 pm
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
Comment by Alastair — June 4, 2007 @ 9:04 pm
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
Comment by stan — June 4, 2007 @ 9:31 pm
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
Comment by Kalle Johansson — June 13, 2007 @ 12:07 am
@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″);
Comment by Alastair — June 13, 2007 @ 12:22 am
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 ?
Comment by kasun111 — June 29, 2007 @ 2:57 am
[…] 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) […]
Pingback by links for 2007-07-07 « things i am or once was — July 10, 2007 @ 2:44 pm
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!
Comment by Jason Boxman — July 16, 2007 @ 10:13 pm
Hey Jason nice work
Comment by Alastair — July 16, 2007 @ 11:10 pm
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”}
=====================================================
Comment by SweZin — July 21, 2007 @ 7:55 pm
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
Comment by Ivan — July 23, 2007 @ 8:56 am
Excellent guide, thank you very much. How would you recommend extending this to support queued upload (ie, one file at a time)?
Comment by Rocktansky — August 2, 2007 @ 2:47 pm
[…] Vixiom Axioms » Multiple File Upload with Flash and Ruby on Rails 플래시와 ë ˆì¼ì¦ˆë¥¼ ì´ìš©í•œ íŒŒì¼ ì—…ë¡œë“œ (tags: flash flex í”Œë ‰ìŠ¤ file upload) […]
Pingback by links for 2007-08-08 — August 8, 2007 @ 9:25 am
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
Comment by Amit Yadav — August 9, 2007 @ 8:39 am
Hi Amit,
The solution is to buy a mac :)
Could you provide more information on what is not working?
Comment by Alastair — August 9, 2007 @ 8:52 am
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?
Comment by Ken — August 25, 2007 @ 5:15 pm
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.
Comment by sunds2 — September 25, 2007 @ 8:53 pm
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).
Comment by Alastair — September 25, 2007 @ 11:02 pm
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?
Comment by sunds2 — September 26, 2007 @ 2:45 pm
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.
Comment by Alastair — September 26, 2007 @ 4:02 pm
Thanks Alastair.
Comment by sunds2 — September 26, 2007 @ 6:57 pm
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.
Comment by Tammam — September 27, 2007 @ 9:31 pm
Sorry i forgot to mention.
your screen shot says “complete” mine just says “100%” and stops…
Comment by Tammam — September 27, 2007 @ 9:34 pm
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 ?
Comment by Lorenzo Gonzlez — October 2, 2007 @ 4:02 pm
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
Comment by Neil — October 3, 2007 @ 3:46 am
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
Comment by Neil — October 3, 2007 @ 3:50 am
@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?
Comment by Richard — October 31, 2007 @ 2:33 am
[…] 利用Googleæœç´¢ï¼Œå‘çŽ°æ— æ•°çš„äººä¹Ÿåœ¨è¯¢é—®åŒæ ·çš„é—®é¢˜ã€‚åŽæ¥åœ¨è¿™ç¯‡ä»‹ç»ç”¨Flex实现的批é‡ä¸Šä¼ çš„æ–‡ç« åŽçš„评论里é¢ï¼Œæ‰¾åˆ°äº†ä¸€ä¸ªå«åšâ€œTimothee Groleauâ€çš„哥们的“自问自ç”â€ï¼Œç»ˆäºŽè§£å¼€äº†è¿·å›¢ï¼šFlashPlayer在触å‘å¹¶æ‰§è¡Œç”¨æˆ·å®šä¹‰çš„è„šæœ¬ï¼ˆå°±æ˜¯ä½ ç¼–å†™çš„ActionScript)时,会é‡ç½®â€œè„šæœ¬è¶…æ—¶å€¼â€ï¼ˆä¸Šæ–‡æåˆ°çš„15ç§’ï¼‰ã€‚è¿™æ ·ï¼Œæˆ‘ä»¬å¯åœ¨æŸä¸€ä¸ªâ€œé©¬ç”²MovieClipâ€ä¸Šç»‘定一个onEnterFrameäº‹ä»¶ï¼Œè®©å®ƒä¸æ–地(é€å¸§ï¼‰æ‰§è¡Œã€‚最简å•çš„åšæ³•就是: […]
Pingback by ActionScript 3 Lover » upload-causing-flashplayer-slowly — November 1, 2007 @ 3:03 am
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
Comment by Charles — November 21, 2007 @ 10:53 pm
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
Comment by Arfon — December 11, 2007 @ 8:58 am
@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.
Comment by Alastair — December 11, 2007 @ 9:18 am
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
Comment by Arfon — December 11, 2007 @ 9:47 am
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).
Comment by Alastair — December 11, 2007 @ 10:49 am
Alastair you’re a star. Thanks so much, it’s all working perfectly now.
Comment by Arfon — December 11, 2007 @ 10:58 am
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 :).
Comment by EnvyGeeks — December 11, 2007 @ 9:08 pm
Can you publish a merb version of the same tutorial? Thx.
Comment by mike — December 11, 2007 @ 9:14 pm
@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 :)
Comment by Alastair — December 11, 2007 @ 10:52 pm
@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.
Comment by Alastair — December 11, 2007 @ 10:55 pm
Consider Merb if you need authentication support for your uploads . . .
http://merb.devjavu.com/attachment/ticket/82/fixation_exclusion_white_list.diff
Comment by Jon — January 15, 2008 @ 2:50 pm
So there is no way of getting this to work in a Rails setting in which authentication(Basic Authentication) is required?
Comment by Harm — January 16, 2008 @ 9:10 am
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
Comment by Pablo — January 28, 2008 @ 4:50 pm
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.
Comment by Noah Horton — January 29, 2008 @ 9:09 pm
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
Comment by Ivy — January 30, 2008 @ 8:45 pm
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?
Comment by Alex Kira — February 11, 2008 @ 8:56 am
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…
Comment by Alex K