# Flash Upload and Ruby

**URL:** <https://www.ruby-forum.com/t/flash-upload-and-ruby/48189>\
**Category:** Rails\
**Created:** [November 15, 2005, 5:33pm UTC](https://www.ruby-forum.com/t/flash-upload-and-ruby/48189 "2005-11-15T17:33:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![heavysixer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/6de8d8/32.png) [@heavysixer](https://www.ruby-forum.com/u/heavysixer)\
**Post date:** [November 15, 2005, 5:33pm UTC](https://www.ruby-forum.com/t/flash-upload-and-ruby/48189/1 "2005-11-15T17:33:20Z")

</div>

* * *

## Please forgive me if you get this twice, I sent it yesterday but never saw it appear on the list.

Hi Rubiests,  
This is my first posting to the rails group so please forgive me if this  
is  
a well-covered question (though I did check the wiki and the faqs on the  
site).

I am trying to create a Flash-based bulk uploader for my first Ruby  
project.  
You can see an example of the uploader running in a PHP script here:

[http://www.flavoredthunder.com/dev/flash/flashUploader/](http://www.flavoredthunder.com/dev/flash/flashUploader/)

This works swimmingly in php but there is no joy in Ruby.

I am using version “0.14.3” of Rails and “1.8.2” of Ruby on a Mac OS X  
"10.3  
"

The webbrick spits out a very unceremonious error when I try to call my  
“admin/flash\_create” action:

[14/Nov/2005:23:10:01 PST] “POST /admin/flash\_create HTTP/1.1” 500 8175

- → /admin/flash\_create

When doing some research on the problem I found a bug report on the  
rails  
site:

[http://dev.rubyonrails.org/ticket/2277](http://dev.rubyonrails.org/ticket/2277)

They suggested installing the flash-fix plugin. I have installed the  
flash-fix plugin into my vender/plugin directory but was unsure what to  
do  
past that.

My very basic method in the admin\_controller is:

def flash\_create  
@params[‘Filedata’][‘content _name’] =  
File.basename(@params[‘Filedata’][‘tmp\_name’].original\_filename).gsub(/[^a-zA-Z0-9.]/,  
'_’)  
@params[‘Filedata’][‘content\_type’] =  
@params[‘Filedata’][‘tmp\_name’].content\_type.chomp  
@params[‘Filedata’][‘data’] = @params[‘Filedata’][‘tmp\_name’].read  
@params[‘Filedata’].delete(‘tmp\_name’)  
@photo = Photo.new(@params[‘Filedata’])  
@photo.save  
end

“Filedata” is the field that Macromedia specifies for their multipart  
file  
transfers

Any help is greatly appreciated!

thanks,  
Mark

---

<div class="post-metadata">

**Author:** ![heavysixer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/6de8d8/32.png) [@heavysixer](https://www.ruby-forum.com/u/heavysixer)\
**Post date:** [November 15, 2005, 5:51pm UTC](https://www.ruby-forum.com/t/flash-upload-and-ruby/48189/2 "2005-11-15T17:51:24Z")

</div>

Hi,  
take a look at this:

[http://weblog.bubbleshare.com/articles/2005/10/20/flash-8-file-upload-](http://weblog.bubbleshare.com/articles/2005/10/20/flash-8-file-upload-)  
headaches

Hoipe it helps,

Ettore

Il giorno 15/nov/05, alle ore 17:32, M Daggett ha scritto:

---

<div class="post-metadata">

**Author:** ![heavysixer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/6de8d8/32.png) [@heavysixer](https://www.ruby-forum.com/u/heavysixer)\
**Post date:** [November 15, 2005, 6:39pm UTC](https://www.ruby-forum.com/t/flash-upload-and-ruby/48189/3 "2005-11-15T18:39:34Z")

</div>

Yes,  
I think he is the one that wrote the plugin. I did incorporate it into  
my  
rails app but no joy.

---

<div class="post-metadata">

**Author:** ![heavysixer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/6de8d8/32.png) [@heavysixer](https://www.ruby-forum.com/u/heavysixer)\
**Post date:** [November 16, 2005, 4:27am UTC](https://www.ruby-forum.com/t/flash-upload-and-ruby/48189/4 "2005-11-16T04:27:29Z")

</div>

Update!  
I was able to get the Flash Ruby synergy all dialed in (sorta).  
I updated my blog with the code and details:

> **[CollColl.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=collcoll.com)**
>
> Painless, quick delivery of your domain name. Fast and professional service.

I am able to get uploads that store the files on the physical drive as  
opposed to as a blob in the database.  
At first I was a bit confused why this was but then it dawned on me  
that I was creating the object in the first method.

def new  
@picture = Picture.new  
… show the upload page  
end

then when flash was called to submit to the page I got an error  
because my picture object was nil. I can only assume this is because  
the ruby and flash upload happens outside of the scope of ruby’s  
session object.

When the file was submitted ruby would have no context in which to  
view the request. This brings up an interesting question. I originally  
inteded on doing some sort of lock/key system whereby my first method  
would define a variable and then pass it along to flash so that it  
could be embeded into the post (and authenticated by ruby). This would  
keep simultanious users from clobbering each other and prevent people  
from subverting my upload process.

Here is another problem related to the first. Presently my app  
authenticates the user before the URL filter. If the user is not  
authenticated then it redirects them to the login. Knowing that I  
cannot append anything side the actual post object I guess I am left  
with only one option which is to append it to the url string.

Is this wise, does anyone have a better idea?

Thanks,  
Mark

On 11/15/05, M Daggett [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > This is my first posting to the rails group so please forgive me if this
> 
> site:
> 
> > def flash\_create  
> > @photo.save  
> > Mark  
> > removed\_email\_address@domain.invalid
> 
> ## –
> 
> I am Mark Daggett and I approve this message.

–
