File Upload in flex
private var fileRef:FileReference
private function doCreationComplete():void
{
fileRef= new FileReference();
fileRef.addEventListener(Event.COMPLETE, completeHandler);
fileRef.addEventListener(ProgressEvent.PROGRESS, fileRef_progress);
fileRef.addEventListener(Event.SELECT, doSelect );
}
public function doBrowse( event:Event ):void
{
try
{
fileRef.browse();
}
catch (error:Error)
{
trace("Unable to browse for files.");
}
}
public function doSelect( event:Event ):void
{
txtPhoto.text = fileRef.name;
}
public function doSubmit( event:Event ):void
{
var request:URLRequest = new URLRequest( "http://localhost:8080/JustSms/co开发者_Go百科m/contacts/serviceImpl/CSVReader" );
var vars:URLVariables = new URLVariables();
vars.person = txtPerson.text;
request.data = vars;
fileRef.upload( request );
}
function completeHandler(event:Event):void
{
trace("uploaded");
}
private function fileRef_progress(evt:ProgressEvent):void
{
progressBar.visible = true;
}
Error #2044: Unhandled IOErrorEvent:. text=Error #2038: File I/O Error. at uploadcontacts/doCreationComplete()[D:\Flexspace\SMS\src\uploadcontacts.mxml:17] at uploadcontacts/___TitleWindow1_creationComplete()[D:\Flexspace\SMS\src\uploadcontacts.mxml:3] at flash.events::EventDispatcher/dispatchEventFunction()
What is this error?how can i handle this ...and is it correct way to requet Servltet ?? plz help me..
Download something like Fiddler or Firebug, and tell us what the HTTP traffic is.
You should also add error event listeners to the FileReference object so that you can trap the errors when they happen. (and they might happen for a number of reasons out of your control...). All the Flex documents show you examples of which errors to trap. The only problem is that sometimes you get two errors for one request. e.g., in my experience, if I get an HTTP_STATUS error, I will also get an IO_ERROR. Seems dumb to me, but maybe Flex/Adobe has their reasons.
精彩评论