I am using flex 3, actionscript 3 and rails for developing a small
application. I want to upload a file on server in a particular
directory but i am getting the IO error at run time. Please help me
fixing this bug.
Code i used is:
---------------------------application.rb------------------------
# Filters added to this controller apply to all controllers in the
application.
# Likewise, all the methods added will be available for all
controllers.
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
# See ActionController::RequestForgeryProtection for details
# Uncomment the :secret if you're not using the cookie session store
protect_from_forgery # :secret => '3a8f77511f4633ed7c0cb6065d614fec'
def upload_file
file_data = params[:Filedata]
file_name = params[:Filename].to_s
file_path = params[:folder].to_s
File.open(file_path + "/" + file_name, "wb") { |new_file|
new_file.write(file_data.read) }
render(:xml => "<success/>")
end
end
------------------------PdfStore.mxml----------------
<?xml version="1.0" encoding="utf-8"?>
<!--mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" xmlns:pom="com.PdfStore.components.*"
layout="vertical" backgroundGradientColors="[#ffffff, #c0c0c0]"
horizontalAlign="center" verticalAlign="top" width="100%"
height="100%"-->
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:pom="com.PdfStore.components.*"
layout="vertical"
backgroundGradientColors="[#ffffff, #c0c0c0]"
horizontalAlign="center"
verticalAlign="top"
width="100%"
height="100%">
<mx:Accordion width="463" height="300">
<pom:AvailablePdfs/>
<pom:UploadPdf/>
</mx:Accordion>
</mx:Application>
----------------------------------UploadPdf.mxml---------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%"
height="100%" label="Upload Pdf">
<mx:Script>
<![CDATA[
/*function openf():void {
var fileTypes:FileFilter = new FileFilter("Pdf (*.pdf)", "*.pdf;
");
var allTypes:Array = new Array(fileTypes);
var fileRef:FileReference = new FileReference();
//fileRef.addEventListener(Event.SELECT, selectHandler);
fileRef.browse(allTypes);*/
import mx.rpc.http.HTTPService;
import mx.collections.ArrayCollection;
import flash.net.FileReferenceList;
import flash.net.FileReference;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
private static const fileFolder:String = "myUploads";//com/PdfStore/
assets";// //this folder is located in rails_file_transfer\public\
[Bindable]
private var filesToUpload:ArrayCollection = new ArrayCollection();
[Bindable]
private var uploadedFiles:ArrayCollection = new ArrayCollection();
//include "scripts/uploadScript.as";
]]>
</mx:Script>
<mx:Script source="uploadScript.as"/>
<mx:Form height="217" width="499">
<mx:FormItem required="true" label="Select File">
<mx:VBox height="130">
<mx:TextInput id="pdflocationTI" width="250"/>
<mx:List x="0" y="0" width="100%" height="100%" id="localFiles"
dataProvider="{filesToUpload}"></mx:List>
<!--mx:Button id="browseButton" label="Browse" click="openf()"/-->
</mx:VBox>
</mx:FormItem>
<mx:FormItem width="349" height="64">
<mx:Button id="uploadButton" label="Upload" width="68"
click="uploadFiles()"/>
<mx:ProgressBar labelPlacement="center" width="251" height="21"
id="pb" mode="manual" direction="right"/>
</mx:FormItem>
</mx:Form>
</mx:HBox>