Solved

Rails and Flash Filereference - receiving HTTP 422

Posted on 2009-05-06
17
792 Views
Last Modified: 2013-11-13
Trying create a multiple file uploader in flash using RoR. I'm using AS3 scripts I use to send to PHP. Modified it a bit, and created some rails script like below...

My thoughts: It may be the auth token I need to validate, but I tried passing that in POST and no luck.

Anyone know simply how to upload files from Flash Actionscript to Ruby on Rails???
class DataFile < ActiveRecord::Base

 

  def self.save(data, name, directory)

  		path = File.join(directory, name)

  		File.open(path, 'wb') do |file|

  			file.puts data.read

		  end

		  #File.open(path, "wb") { |f| f.write(params[:filedata].read) }

  end

end

 

class UploadController < ApplicationController

	def index	

		data = params[:filedata]

		name = params[:Filename]

		

		directory = "public/data"

		

		@data_file = DataFile.save(data, name, directory)

 

		render :nothing => true

	end

end

Open in new window

0
Comment
Question by:bizzark
  • 8
  • 7
17 Comments
 

Author Comment

by:bizzark
ID: 24358686
...anyone?   Or anyone know how to pass vars from Flash to a Ruby object in Ruby 2.0? I guess I'll try that next..
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 24412798

I am not too sure about the RoR part, but here is an article on how to send it to a PHP script...

http://scoopmedia.be/uploading-files-using-actionscript-30-and-php


I assume, this would be the same with any server-side environment...



rp / ZA
0
 

Author Comment

by:bizzark
ID: 24414585
Yeah thanks.. doesn't do me much good. I've been working with PHP for a while, I'm trying to switch to Rails.
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 24414689

"Anyone know simply how to upload files from Flash Actionscript to Ruby on Rails???"


I gave you the flash part, because that is my responsibility...  if you need help only with the Rails code, and your actionscript is working perfectly, then I would have a Mod post this question in the proper area...


And since your question was worded in a way that make it sound like you believe you can use Flash to do system uploads, I wanted to give you that information...  


rp / ZA
0
 

Author Comment

by:bizzark
ID: 24414881
I had the AS part, like I said above.. I've been using a Flash upload I made for PHP for a while, but I just need help sending it to Rails.
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 24414956

the question was just added to the wrong area then...  if you want, I can have it removed from the AS area.

rp / ZA
0
 

Author Comment

by:bizzark
ID: 24414999
Sure if you think so. But it is an AS question also. I want to know specifically what is needed to communicate with Ruby in AS (if there is anything different)..
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Expert Comment

by:rascalpants
ID: 24415070

I believe I said it above... you communicate with all server-side code the same way...  it is the method that might change...

like Flash Remoting VS Web Services VS sending a QueryString.  it is all the same, and if it is working for PHP, then it is most likely your RoR code that is the issue.

Also, since you have not posted any Actionscript, there there is no way for a Flash person to help you with the Flash part  :)


rp / ZA

0
 

Author Comment

by:bizzark
ID: 24415082
Alright.. well another thing was I wasn't sure if I needed to pass Auth codes from Rails into flash for it to work too.
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 24415154

Since I have never worked with RoR, I don't know the specifics to what is needed as a call...

if you are needing to pass parameters in your call to the server, then that is simple enough...


what version of AS are you using?   post your code that does this part...


rp / ZA
0
 

Accepted Solution

by:
bizzark earned 0 total points
ID: 24418392
Hey, I figured it out! Kept messing with it. I turned off the authenticity token using:

skip_before_filter :verify_authenticity_token, :only => 'upload_action'

Then I looked in the Shell while I performed actions through html (which I got working), and Flash and saw that the variables had different names, so I had to change that

=)

0
 
LVL 22

Expert Comment

by:rascalpants
ID: 24421871
so there was nothing in the Flash that needed updating?


rp / ZA
0
 

Author Comment

by:bizzark
ID: 24424167
No, but I needed to know what Flash sends its file vars as.. it kinda was, but yeah not really.
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 24424217
lol...  then I guess that should have been your question...  and I would have said, that depends on what method you use to connect to the server  ;)


rp / ZA

0
 

Author Comment

by:bizzark
ID: 24434880
Thanks. my question for the most part is answered. The only dilemma I'm facing now is how to actually use the authenticity_code and pass it to Rails. I can receive it in Flash, but I'm not able to get rails to accept it.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Grammars for C C++ and java 1 114
bigDiff challenge 17 84
Choosing the right language for new project 8 61
is this a cms? 8 35
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now