Page 1 of 1

RUBY ON RAILS 2.3.8

Posted: Sun Apr 24, 2011 11:11 pm
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

Re: RUBY ON RAILS 2.3.8

Posted: Mon Apr 25, 2011 1:32 pm
by support
Thanks for the feedback