Overriding FileReference Upload
Hi Guys,
I'm looking to extend the FileReference class and override the upload method, using my own implementation. Firstly I would like to know if it is possible to view the current implementation code in the upload class. Secondly, how go about creating a custom HTTP request? I mean if I wanted to create a request from scratch how would I do this? Using sockets? Thirdly can I use the HTTPService class to initiate an upload?
check for permissions on server .
Similar Messages
-
Filereference.upload ... works on localserver but not on webserver
hello;
I'm uploading images via filereference.upload ... works fine when testing on local machine with apache. once I port everything to my web-based server ( shared server with a webhosting company ), the upload fails.
- do not get any errors such as SECURITY_ERROR , HTTP_STATUS , IO_ERROR
- do get 1 PROGRESS event - only 1 - but it already shows 100%
- do get COMPLETE event after a couple of seconds
- do not get UPLOAD_COMPLETE_DATA, but do get it on localhost
- do not get the image on the remote server
- my local php is 5.2 ... webserver php is 4.4 ...
- I have tried setting 757 as file permissions for image directory
- all php, swf, image directories are in the same domain, though in different directories.
- I have tried uploading the image to the same directory as php directory itself
any thoughts?
thanks,
dsdsdsdsdnot exactly what was not working, but my webhost updated my php module to php 5.2, and my uploader works.
-
Flex 3 - CF9 filereference.upload test
Hi
i run a filereference.upload test flex application which uploads a file through a coldfusion server.
i’m using flex 3 and coldfusion 9.
i’m also passing parameters in the URLRequest that points to the upload cfm file.
when i run my test using the built-in web server (Jrun) all seems to work just fine
when i run the same test on a coldfusion instance that runs on Apache web server, it throws a I/O Error…
i suspect i’m missing some kind of a configuration i need to perform when moving to a production setup rather then a development environment…
can anyone guide me through this?
does it have to do with security? on the client? on the server?
i’m still running on localhost…
summery...
attached are the mxml file and the cfm file
works great on built-in server
throws a I/O error when runs through Apache
cheersIf you want to test against another implementation, I wrote a Flex Upload component and CFML script a while back. I've used it regularly on IIS and Apache server (and my localhost) without having to modify the configuration at all. Speaking of the config, Daverns could be totally right ... and this post is not to refute or argue the point about Mod_Security; rather, its only meant as another options to test, since you were having trouble with it on the production server.
The attached Zip archive contains three files: FileUpload.mxml, SampleUsage.mxml, and fileUpload.cfm. The files are heavily commented but feel free to ping me if you have any issues with it.
Good luck! -
FileReference.upload() not working in Firefox
Hi,
i have a strange problem - my Flex application uses the FileReference.upload() to upload images to the server. ServerSideScript ist pure PHP.
It is working in IE but not in FF
Any help is really appreciated since i'm running out of ideas...
<?php
$target_path = "../xml/akten/dokumente/";
$target_path = $target_path . basename( $_FILES['file']['name']);
if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['file']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
?>
Greetings from Germany
MarkusI am facing the same problem.
Has anyone any solution on this.
Thanks -
Antivirus software breaks FileReference.upload() method...
Hi there,
I'm a Flash developer who's run into an interesting problem since upgrading to AVG 9 (free antivirus software).
I use Flash to facilitate large uploads to websites (eg. video). I've built plently of upload widgets that use Flash's FileReference.upload() method to send a file from a users computer to a webserver.
It seems that since upgrading to AVG 9, the bytesLoaded property of a ProgressEvent is being updated at warp speed - a 30mb file appears sent to a server in less than a second! Which is ridiculous. So in an instant, the bytesLoaded property equals the bytesTotal property. Seemingly an arbitrarily time later, the Event.COMPLETE event fires (I think this arbitrarial illusion is caused by the upload continuing in the background). If everything was running as it's supposed to, this should generally be followed by a DataEvent.UPLOAD_COMPLETE_DATA event firing. But now, because of all this weirdness, no DataEvent.UPLOAD_COMPLETE_DATA event is firing.
After a bit of websurfing I found other developers having problems with this because of virus software - so I've uninstalled AVG and "voila!", Flash now works as it is supposed to when uploading a file again.
I guess I could build a polling timer into my uploader to continually ping the server to check that my upload had complete and grab my upload complete data that way, but that'd be annoying as heck.
Any ideas what's going on? This is kind of a massive problem, ProgressEvent returning bogus bytesLoaded data, isn't it?
Kind regards,
James.James Furey:
I agree in disabling the LinkScanner. Open AVG User Interface, Dbl click on the LinkScanner and Untick the "Enable AVG Search-Shield" and the "Enable Active Surf-Shield" then SAVE the changes made.
eidnolb
Message was edited by: eidnolb -
FileReference.upload response is truncated on Mac
I have flash as3 code that will upload a file to my server using FileReference.upload but when receiving the DataEvent.UPLOAD_COMPLETE_DATA event * on MAC only *, I find that event.data will get truncated after a certain number of bytes/characters (looks to be about 2400 Bytes). I know that my server is returning more data than this because I can see the raw response using an HTTP sniffer program. Is there a reason my response data is getting truncated on macs and is there anything I can do to avoid this truncation?
My server side code is running on ASP.NET and IIS if that is relevant. The Content-Length HTTP Header value also appears to be set correctly. This looks to work on windows (firefox 3.6, chrome, and IE) but fails consistently on mac (firefox, chrome, safari).
Any ideas?I have flash as3 code that will upload a file to my server using FileReference.upload but when receiving the DataEvent.UPLOAD_COMPLETE_DATA event * on MAC only *, I find that event.data will get truncated after a certain number of bytes/characters (looks to be about 2400 Bytes). I know that my server is returning more data than this because I can see the raw response using an HTTP sniffer program. Is there a reason my response data is getting truncated on macs and is there anything I can do to avoid this truncation?
My server side code is running on ASP.NET and IIS if that is relevant. The Content-Length HTTP Header value also appears to be set correctly. This looks to work on windows (firefox 3.6, chrome, and IE) but fails consistently on mac (firefox, chrome, safari).
Any ideas? -
FileReference.upload in JSP problem
Help !!!
We've succesfully implemented file upload via flash in jsp
tomcat (using FileReference.upload() in actionscript 2.0 ), but for
some reason, parameters posted in the url to the file upload
handling script (ej. "uploadScript.jsp?id=1") are lost, ie: the
id=1 is lost.
To double check flash correctly sending params , we've
implemented the same flash object in php and parameters are posted
fine.
Any Ideas, I'm desperate.
thanks.
cCTherefore, can anyone tell me what have happened?The problem is in the scope. Request objects are local to jspService() method (Sorry, i forgot the name). So it's life is not long enough to be found in other pages. For your case, session is the perfect scope.
session.setAttribute() is the smartest. u can use pageContext.setAttribute method also. I do not have any idea about other solutions.
Hafizur Rahman
SCJP -
Getting the response from a FileReference upload
This question is about the "upload" method of the
FileReference class.
Is there any way to read the HTTP response after a file
upload is complete? For example, a user uploads an file to a
server. The server saves the file and assigns it an ID. The server
then writes the ID to the HTTP response. How does the client read
that response?inlineblue wrote:
This was kicked around a while back in the Flexcoders list.
Everyone agrees this would be very useful, but not currently
available. Sigh.
Flexcoders said what? (Am I missing something? Ahh - the date of the original post...)
fileReference.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, uploadComplete);
private function uploadComplete(event:DataEvent):void {
trace(event.data);
getWriter() or getOutputStream() on the servlet response to send "stuff" back... -
Hi, I got a FileRefrence instance for a simple upload and it did work for some time in the past, but now I just can't discover what made it stop woking. Can anyone help me find it out? To simplify, I took only the necessary code (not working as the full version). Here are some details:
1. I'm using Flash Player 9 (this can't change because it is a part of a bigger project). My current host machine is a Windows Vista one. The sandbox is set to network access.
2. The FileReference calls a simple php script hosted at an Apache server (Linux). The script permissions are set to 644 (it works for file uploads coming from plain html pages) and I set the folder permission to 777 just to avoid any other source of errors. Here is the simple code for the php script:
<?php
// receiving variables
$uid = trim($_POST['uid']); // just to check for a post variable that I must send while uploading (won't work even if I revome it)
// a file to check if the script is really called
$myfile = fopen("upload.txt", "wb");
fputs($myfile, "file upload for uid $uid\n");
// receiving the file and saving it
if ($_FILES['Filedata']['name'] != "") {
$newName = preg_replace('/[^a-z0-9_\-\.]/i', "_", $_FILES['Filedata']['name']);
$newName = preg_replace('[ \f\r\t\n]', "_", $newName);
@move_uploaded_file($_FILES['Filedata']['tmp_name'], $newName);
fputs($myfile, ("new received filename: " . $newName . "\n"));
} else {
fputs($myfile, ("no file received\n"));
fclose($myfile);
?>
This script writes a file named "upload.txt" so I know it was really called. If I run it directly from the browser, everything is ok.
3. My AS3 code just starts the browsing for a file (I'm using a 500k mp3 to test). By following the program trace I see that the upload actually happens, but when it finishes, I get an IO error (I'm using the very same url address for the script that I use at the browser). When I check the server, I see that no "upload.txt" file is written, so the script was really not found. Here is some of the AS3 code I'm using:
private var urlSend:URLRequest = new URLRequest("my address to the php script (http)");
private var urlData:URLVariables = new URLVariables();
private var fileTansfer:FileReference = new FileReference();
private function uploadFile():void { // call by a button click
this.urlData.uid = "1";
this.urlSend.method = URLRequestMethod.POST;
this.urlSend.data = this.urlData;
this.configureListeners(this.fileTansfer); // all listeners are correctly set
this.fileTansfer.browse(new Array(new FileFilter("Audio files", "*.mp3")));
// listeners set here
private function selectHandler(event:Event):void {
var file:FileReference = FileReference(event.target);
trace("selectHandler: name=" + file.name + " URL=" + this.urlSend.url); // prints correclty
file.upload(this.urlSend);
As I said before, I get traces from progress handler and when it reaches the end, I get the IO error message:
ioErrorHandler: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2038: Erro do arquivo de E/S. URL: (my correct url here)"]
Just for checking I add a Loader instance and used its "load" method with the same "urlSend" variable. It worked and the php script generated the output file...
Does anyone know what's happening? Could it be some permission problem? Why can't the FileReference find my script assuming its url is ok?
Thank you in advance!How did you resolve the above error ? Thanks.
-
How can I pass a path to the FileReference upload function?
i don't understand how can i upload a file from the browse
function after you've selected a file. since FileReference.name
returns
only the filename w/extension and not the path, how can i
work around this?
i understand the security implications with a swf and the
such, but what to do? and using an AIR app is not an option for me.
i have a .net web service in place and it works with a hard
coded string, such as in the snippet below, but how are people
doing this by using the browse method as oppossed to a static
string?
i get an IO error with just the browse() returned filename,
which makes sense when you think about it. path, path, path...ARGH!
thanks folks...
-fdi don't understand how can i upload a file from the browse
function after you've selected a file. since FileReference.name
returns
only the filename w/extension and not the path, how can i
work around this?
i understand the security implications with a swf and the
such, but what to do? and using an AIR app is not an option for me.
i have a .net web service in place and it works with a hard
coded string, such as in the snippet below, but how are people
doing this by using the browse method as oppossed to a static
string?
i get an IO error with just the browse() returned filename,
which makes sense when you think about it. path, path, path...ARGH!
thanks folks...
-fd -
Filereference Upload - A script in this movie is causing Adobe Flash...
This appears to be a sore topic these days. I have searched and found a large number of postings with this flash player message (A script in this move is causing Adobe Flash Player -n- to run slowly. If it continues...) But I haven't found a posting where it is resolved. I am trying to provide my client with an upload script. What I have so far works on small files but results in the aforementioned error message on large files. I saw a message a few days ago that talked about writing an onEnterFrame routine in a dummy movie clip that increments a counter, but there were no details about what that code might look like. I have tried several iterations of that logic to no avail. I know I am not the only one with this problem, and I do need to find a solution. I don't think that the server php settings are the problem. Does anyone have any ideas?
Thanks in advance,
GW
Action script from Layer 1: Frame 1 -
_global.states = Array("AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FM", "FL", "GA", "GU", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MH", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "MP", "OH", "OK", "OR", "PW", "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VI", "VA", "WA", "WV", "WI", "WY");
_global.states.sort();
_global.keepMemory = false;
this.mc_uploadCtr.mc_stateError._visible = false;
this.mc_uploadCtr._visible = false;
this.mc_uploadCtr.enabled = false;
// Get upload data
var xmlData=new XML();
xmlData.ignoreWhite=true;
xmlData.onLoad = function(ok:Boolean) {
if (ok) {
processXmlData(this);
} else {
dt_main.text = "XML did not load";
function processXmlData(xml:XML) {
_global.notifyToEmail = xml.firstChild.childNodes[0].childNodes[0].nodeValue;
_global.notifyFromEmail = xml.firstChild.childNodes[1].childNodes[0].nodeValue;
_global.notifyFromName = xml.firstChild.childNodes[2].childNodes[0].nodeValue;
System.useCodepage = true;
xmlData.load('uploadData.xml');
_global.keepInMemory = function(keep:Boolean) {
if ((keep == true) and (_global.keepMemory == false)) {
_global.keepMemory = true;
this.createEmptyMovieClip("dummy_mc", 999);
this.dummy_mc.onEnterFrame = function () {
while(_global.keepMemory == true) {
var count:Number = count + 1;
} else {
if (_global.keepMemory = true) {
_global.keepMemory = false;
this.dummy_mc.unloadMovie();
stop();
Action Script from upload movie clip:
import flash.net.FileReference;
var progressBar:MovieClip;
var reference:FileReference = new FileReference();
var referenceListener:Object = {};
var scriptLocation:String = 'uploader.php';
var progressBarHeight:Number = 10;
var progressBarY:Number = 50;
var progressBarColor:Number = 0x66ccff;
reference.addListener(referenceListener);
referenceListener.onSelect = activateUploadButton;
referenceListener.onProgress = updateProgress;
referenceListener.onComplete = checkIn;
referenceListener.onHTTPError = handleError;
referenceListener.onIOError = handleError;
referenceListener.onSecurityError = handleError;
btn_uploadFile._visible = false;
btn_selectFile.onRelease = choose;
btn_uploadFile.onRelease = uploadCurrent;
function activateUploadButton():Void {
display_txt.text = reference.name;
btn_uploadFile._visible = true;
btn_uploadFile.enabled = true;
function choose():Void {
reference.browse([{description:'Images (*.ai, *.drw, *.jpg, *.jpeg, *.gif, *.pdf, *.png, *.psd, *.psp, *.tif,)', extension:'*.ai; *.drw; *.jpg; *.jpeg; *.gif; *.pdf; *.png; *.psd; *.psp; *.tif'}]);
function handleError(errorName:String, detail:Object):Void {
restart();
if (arguments.length === 2) {
if (typeof detail === 'number') {
display_txt.text = 'HTTP Error #'+detail;
} else {
display_txt.text = 'Security Error: '+detail;
} else {
display_txt.text = 'IO Error';
function makeProgressBar(x:Number, y:Number):MovieClip {
var bar:MovieClip = createEmptyMovieClip('progressBar_mc', 0);
bar._visible = false;
bar.beginFill(progressBarColor);
bar.lineTo(display_txt._width, 0);
bar.lineTo(display_txt._width, progressBarHeight);
bar.lineTo(0, progressBarHeight);
bar.lineTo(0, 0);
bar.endFill();
bar._width = 0;
bar._visible = true;
bar._x = x;
bar._y = y;
return bar;
function restart():Void {
removeMovieClip(progressBar);
display_txt.text = '';
btn_uploadFile._visible = false;
btn_selectFile._visible = true;
function updateProgress(fileReference:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
display_txt.text = fileReference.name+' - '+Math.ceil((bytesLoaded/bytesTotal)*100)+'%';
progressBar._width = Math.ceil(display_txt._width*(bytesLoaded/bytesTotal));
function uploadCurrent():Void {
btn_selectFile._visible = false;
btn_uploadFile.enabled = false;
progressBar = makeProgressBar(0, progressBarY);
_global.keepInMemory(true);
reference.upload(scriptLocation);
function checkIn():Void {
_global.keepInMemory(false);
moveFile();
notify()
restart();
function moveFile():Void {
_global.uploadedFile = (_global.uploadFolder + '/' + reference.name);
// var lv_result:LoadVars = new LoadVars();
// var lv_move = new LoadVars();
// lv_move.fileName = reference.name;
// lv_move.rootFolder = (_global.rootFolder);
// lv_move.sourceFolder = (_global.uploadFolder);
// lv_move.targetFolder = (_global.uploadFolder);
// lv_move.sendAndLoad("mover.php", lv_result, "POST");
function notify():Void {
var st_companyName:String = ('<tr><td>Company name:</td><td>'+_global.companyName+'</td></tr>')
var st_contactName:String = ('<tr><td>Contact name:</td><td>'+_global.contactName+'</td></tr>')
var st_phoneNumber:String = ('<tr><td>Phone number:</td><td>'+_global.phoneNumber+'</td></tr>')
var st_address:String = "";
if (_global.address2 <> "") {
st_address = ('<tr><td>Address:</td><td>'+_global.address1+'</td></tr><tr><td> </td><td>'+_global.address2+'</td></tr><tr><td> </td><td>'+_global.addressCity+', '+_global.addressState + ' ' + _global.addressZip + '</td></tr>');
} else {
st_address = ('<tr><td>Address:</td><td>'+_global.address1+'</td></tr><tr><td> </td><td>'+_global.addressCity+', '+_global.addressState+' '+ _global.addressZip + '</td></tr>');
var st_email:String = ('<tr><td>E-Mail:</td><td>'+_global.email+'</td></tr>')
var st_quantity:String = ('<tr><td>Quantity:</td><td>'+_global.quantity+'</td></tr>')
var st_sides:String = ('<tr><td>Sides:</td><td>'+_global.sides+'</td></tr>')
var st_paperWeight:String = ('<tr><td>Paper weight:</td><td>'+_global.sides+'</td></tr>')
var st_jobDescription:String = ('<tr><td>Desc/Title of job:</td><td>'+_global.jobDescription+'</td></tr>')
var st_uploadedFile:String = ('<tr><td>Uploaded file:</td><td>'+_global.uploadedFile+'</td></tr>')
var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
if (success) {
} else {
var lv_notify = new LoadVars();
lv_notify.sender_fromEmail = _global.notifyFromEmail;
lv_notify.sender_toEmail = _global.notifyToEmail;
lv_notify.sender_fromName = _global.notifyFromName;
lv_notify.sender_subject = ('File received from ' + _global.companyName);
lv_notify.sender_message = ('<table width="550" border="1" align="left">' + st_companyName + st_contactName + st_phoneNumber + st_address + st_email + st_quantity + st_sides + st_paperWeight + st_jobDescription + st_uploadedFile + '</table>');
lv_notify.sendAndLoad("sendmail.php", result_lv, "POST");
return;
uploader.php -<?php
if ($_FILES['Filedata']['name']) {
upload_max_filesize = 100M;
post_max_size = 100M;
move_uploaded_file($_FILES['Filedata']['tmp_name'], 'uploads/' . basename($_FILES['Filedata']['name']));
?>Thank you, your answer was helpful. The problem was occuring before I entered the the code you referred to. But your response made me realize that the problem did, indeed, have to do with code that was running during the upload. I isolated the problem to the progress bar logic, which I suspect is not a coding error, but just too many cycles for the player to put up with during a long upload. I am now searching for another method of displaying upload status without a tight piece of code that loops a lot.
Thank you again kglad! -
IO Error after FileReference.upload()
I was working with FileReference to upload to an server and
the upload was successfully completed, but for some reason I was
getting an IOErrorEvent.IO_ERROR after the upload and the
Event.COMPLETE / DataEvent.COMPLETE do not dispatch.
I found the solution to create an .htaccess file with:
SECFILTERENGINE OFF
SECFILTERSCANPOST OFF
... but my host will not do this.
Is there a way to fix it?
_steffenHi Steffen,
I've not seen this problem. Could you please provide a little
more information? What is the backend server platform you're using?
PHP, ColdFusion, ASP, ... ?
Also, have you listened to the HTTP_RESPONSE_STATUS event,
and examined some the status property?
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/HTTPStatusEvent.htm l
-Erica -
Exception Handling for FileReference Upload
Hi There,
I try to find a solution for my exceptions I throw on validating the uploaded file. Every time there is a validation or io or whatever problem on the server side I do throw an AMF exception but unfortunatelly the FileRefernce class identifies this as I/O error 2038.
Whatever I do I'm not able to retrieve the message I added to the AMF exception. Does anybody found a workaround for this?
My only solution is to get pass the upload as successfull but store the error in session or db and make another request to check if there was an error and rethrow the AMD exception there.
r. SandorWHEN OTHERS
THEN
RAISE;Never do this.
It hides where the "others" exception actually occurred.
SQL> select line, text from user_source where name = 'P' order by line;
LINE TEXT
1 procedure p as
2 l_num number;
3 begin
4 l_num := 42 / 0;
5 end;
SQL> exec p;
BEGIN p; END;
ERROR at line 1:
ORA-01476: divisor is equal to zero
ORA-06512: at "SCOTT.P", line 4
ORA-06512: at line 1
SQL> select line, text from user_source where name = 'P' order by line;
LINE TEXT
1 procedure p as
2 l_num number;
3 begin
4 l_num := 42 / 0;
5 exception
6 when others
7 then
8 raise;
9 end;
SQL> exec p;
BEGIN p; END;
ERROR at line 1:
ORA-01476: divisor is equal to zero
ORA-06512: at "SCOTT.P", line 8 --<<< the reference to line 4 is gone.
ORA-06512: at line 1(although it's easy to figure out in this case) -
Using Firefox to FileReference.upload but postback with IE cookie
I don’t know how long it took me to finally figured out
that
upload is actually passing back the IE cookie when I am using
FireFox. This is absolutely the strangest thing.
I am using ASP.NET. The page I am using requires
authentication, so I need to read the cookie for user login
information. To my surprise, when I am logged in as User ONE on
Firefox and upload a file, I received User TWO from IE’s
login. I changed to login as User THREE in IE, the upload in
FireFox passed back User THREE.
I tried deleting all cookies from IE and FireFox, but Flash
still persists on sending back User Three, even though IE cookies
don’t exist anymore.
I am able to upload files correctly, just uploading to the
wrong user's account because of the wrong cookie. I am posting back
to the same aspx page. I also set up 2 separate servers and both
results are the same.
Can someone explain to me why this is, and what I am doing
wrong? How do I make it post back like a normal ASP.NET post back,
because I might need the session cookie.Hi,
Please also see [https://support.mozilla.org/en-US/kb/Problems%20using%20Facebook%20in%20Firefox this.] -
Uploading csv files and reading them from server
I want to read a csv file.From Flex i am able to select the
file but when i pass it to the server using struts
FileUploadInterceptor , am not able to pass the file to the
server.FileUploadInterceptor in struts2 processes the request only
if its instance of MultiPartRequestWrapper.Is there any way in Flex
where i can pass the request as a instance of this.Is there any
other way in which i can read the file from the server after
uploading it through flex.Code is as follows :
1)MXML File :
?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Script>
<![CDATA[
import ImportData;
import flash.net.FileReference;
import flash.net.FileFilter;
import flash.events.IOErrorEvent;
[Bindable] var fileRef:FileReference = new FileReference();
private function openFileDialog():void{
fileRef.addEventListener(Event.SELECT, selectHandler);
fileRef.addEventListener(Event.COMPLETE, completeHandler);
fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA
,uploadCompleteHandler);
fileRef.addEventListener(IOErrorEvent.IO_ERROR,onIOError);
try{
var textTypes:FileFilter = new FileFilter("Text Files
(*.txt,*.csv)","*.txt;*.csv");
var allTypes:Array = new Array(textTypes);
//var success:Boolean = fileRef.browse();
var success:Boolean = fileRef.browse(allTypes);
catch(error:Error){
trace("Unable to browse for files.");
private function onIOError(event:IOErrorEvent):void {
trace("In here"+event.text);
trace("In here"+event.toString());
// when a file is selected you upload the file to the upload
script on the server
private function selectHandler(event:Event):void{
//var request:URLRequest = new URLRequest("/importAction");
var request:URLRequest = new URLRequest("
http://localhost:8080/pack1/importAction.action");
try
fileRef.upload(request);
catch (error:Error)
trace("Unable to upload file.");
private function completeHandler(event:Event):void{
trace("uploaded");
// dispatched when file has been uploaded to the server
script and a response is returned from the server
// event.data contains the response returned by your server
script
public function uploadCompleteHandler(event:DataEvent):void
trace("uploaded... response from server: \n" +
String(event.data));
]]>
</mx:Script>
<mx:Button label="Import" id="importBtn"
click="openFileDialog()" height="20" width="90"
styleName="buttonsOnSearchBar"/>
<mx:ComboBox x="23" y="44" borderColor="#ff0000"
themeColor="#ff0000"></mx:ComboBox>
</mx:Application>
2)struts.xml file
<struts>
<package name="pack1"
extends="struts-default,json-default">
<global-results>
<result name="error" type="json"></result>
</global-results>
<global-exception-mappings>
<exception-mapping result="error"
exception="java.lang.Throwable"/>
</global-exception-mappings>
<action name="importAction"
class="routing.ImportAction">
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="basicStack"/>
<result name="success" type="json"></result>
</action>
</package>
</struts>
3)Action Class
package com.om.dh.orderrouting.action;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import org.apache.log4j.Logger;
import com.opensymphony.xwork2.ActionSupport;
public class ImportAction extends ActionSupport{
private String contentType;
private File upload;
private String fileName;
private String caption;
private static final Logger logger =
Logger.getLogger(ImportAction.class);
@Override
public String execute() throws Exception {
* Read File Line by Line.. If the file has more than one
word separated by comma
* return error.
ArrayList<String> symbolList = new
ArrayList<String>();
try{
BufferedReader reader = new BufferedReader(new
FileReader(upload));
String line =null;
String symbol=null;
while((line=reader.readLine())!=null){
StringTokenizer tokenizer = new StringTokenizer(line,"\t");
symbol = tokenizer.nextToken();
if(symbol!=null) symbol = symbol.trim();
if(symbol.length()>0)
symbolList.add(symbol);
}catch(FileNotFoundException fne){
if(logger.isDebugEnabled())
logger.debug("File NotFount ", fne);
for(String symbol1:symbolList)
System.out.print(symbol1+" ");
return SUCCESS;
public String getUploadFileName() {
return fileName;
public void setUploadFileName(String fileName) {
this.fileName = fileName;
public String getUploadContentType() {
return contentType;
public void setUploadContentType(String contentType) {
this.contentType = contentType;
public File getUpload() {
return upload;
public void setUpload(File upload) {
this.upload = upload;
public String getCaption() {
return caption;
public void setCaption(String caption) {
this.caption = caption;
public String input() throws Exception {
return SUCCESS;
public String upload() throws Exception {
return SUCCESS;quote:
Originally posted by:
ived
tried this but does not work...
var request:URLRequest = new URLRequest("
http://localhost:8080/pack1/importAction.action");
request.contentType="multipart/form-data";
in the interceptor it expects the request to be instanceof
MultiPartRequestWrapper...
Further the document says that FileReference.upload() and
FileReference.download() methods do not support the
URLRequest.contentType and URLRequest.requestHeaders parameters.
Any help ??
Maybe you are looking for
-
Nokia c5-03 problems!please help
hello everyone, please somebody can provide me some valuable suggestions for these problems i m having with my newly bought nokia c5-03, i will be gratefull 2 u all. prob 1:GPS is not working ,it always gives error "WAITING FOR GPS". prob 2:some game
-
Material Cost estimate error in CK11N
Hallo friend, While I cost estimate in particular material through CK11N then this error occur as No price could be determined for material/batch 1002769-750/ plant XYZ. Even the material is maintained in BOM and Routing also. What would be the pr
-
Indesign CS5 crash during startup - problem with Graphics.rpln
I work in an architectural company and already several of our computers have experienced this very rare and unusual behaviour. During start up of Indesign (not clicking on any file but just launching Indesign) it crashes with the following error: "Ad
-
Wrong result in Web Intelligence Report
Post Author: shriram81 CA Forum: WebIntelligence Reporting When I run a query for web inteeligence documnet I receive a wrong result. But when I run the same SQL query in SQL analyzer of MS SQL server I get correct result. e.g. I get the same value o
-
Should I uninstall the Old CS5.5?
I installed upgrade of CS6 Web Premium, but still have dreamweaver CS5.5 and other programs present. Should I uninstall the old programs??