RUBY ON RAILS 2.3.8

Upload core product.
Post Reply
ffabreti
Posts: 1
Joined: Sun Apr 24, 2011 11:04 pm

RUBY ON RAILS 2.3.8

Post by ffabreti »

Finally, got it working.
you need to pass authenticity_token via URL and request.cookies via PARAM.

Here is the config
========== in the view =============

Code: Select all

<div>
<APPLET CODE="jfileupload.upload.client.MApplet.class" JAVA_CODEBASE="./" ARCHIVE="lib/jfileupload.jar,lib/httpimpl.jar,lib/chttpclient.jar,lib/clogging.jar" WIDTH="350" HEIGHT="250" NAME="fileupload">
	<PARAM NAME="CODE" VALUE="jfileupload.upload.client.MApplet.class">
	<PARAM NAME="CODEBASE" VALUE="./">
	<PARAM NAME="ARCHIVE" VALUE="/javascripts/lib/jfileupload.jar,/javascripts/lib/httpimpl.jar,/javascripts/lib/chttpclient.jar,/javascripts/lib/clogging.jar">
	<PARAM NAME="NAME" VALUE="fileupload">
	<PARAM NAME="type" VALUE="application/x-java-applet;version=1.4">
	<PARAM NAME="scriptable" VALUE="true">
	<PARAM NAME="url" VALUE="http://<%=request.host_with_port%>/controller/receiveupload?<%=request_forgery_protection_token%>=<%=Rack::Utils.escape(form_authenticity_token)%>">
	<PARAM NAME="paramfile" VALUE="upload">
	<PARAM NAME="mode"   VALUE="http">
	<PARAM NAME="param1" VALUE="cookiename" >
	<PARAM NAME="value1" VALUE=""_#{RAILS_ROOT.split('/').last}_session"" >
	<PARAM NAME="param2" VALUE="cookievalue" >
	<PARAM NAME="value2" VALUE="<%=request.cookies["_#{RAILS_ROOT.split('/').last}_session"]%>">
</APPLET>
</div>

<% form_for :upload, :url => {:action=>:create}, :html=>{:multipart=>true} do |f| %>
  Import File: 
  <%= f.file_field :file %>
  <%= f.submit 'Importar' %>
<% end %>

<%= link_to 'Voltar', ais_path %>

========== in the controller =============

Code: Select all

def receiveupload  #recebe o arquivo do applet e grava no diretório de arquivos recebidos
	@upload = params[:upload]
	@upload.binmode
	f=File.new("#{RAILS_ROOT}/saved/file-#{Time.now.to_s.gsub(/[ :]/,'-')}", "wb")
   	if f and f.write(@upload.read) 
    	         render :nothing => true
	else
		render :nothing => true, :status => 507
	end
   	f.close
  end
Last edited by ffabreti on Tue Apr 26, 2011 12:27 am, edited 2 times in total.

User avatar
support
Posts: 1503
Joined: Sun Jan 27, 2008 6:19 pm

Re: RUBY ON RAILS 2.3.8

Post by support »

Thanks for the feedback

Post Reply