Skip to main content
Participant
November 12, 2009
Question

Pass variables?

  • November 12, 2009
  • 2 replies
  • 454 views

Hello!

I have this code and I'm trying to upload files to the server. I'm using .NET(C#) now I wonder how I can pass the filename, path and so on to the aspx-page?

var fileRef:FileReferenceList = new FileReferenceList();
fileRef = new FileReferenceList();

var uploadURL:URLRequest = new URLRequest();
var uploadPhotoString:String = "http://localhost/cs/upload.aspx";
uploadURL.url = uploadPhotoString;

function fileSelectHandler(event:Event):void{

for each(var fileToUpload:FileReference in fileRef.fileList){
  uploadSingleFile(fileToUpload);
  lblUpload.htmlText = fileToUpload.name + "<br />";
}
}

function uploadSingleFile(file:FileReference):void{
file.upload(uploadURL);
file.addEventListener(Event.COMPLETE, completeHandler);
}

function completeHandler(event:Event):void{
trace("Uppladdningen lyckades");

}

btnUpload.addEventListener(MouseEvent.MOUSE_DOWN, reportClick);

function reportClick(event:MouseEvent) {
fileRef.browse();
fileRef.addEventListener(Event.SELECT, fileSelectHandler);
fileRef.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
};

function ioErrorHandler(event:IOErrorEvent):void {
        trace("Det uppstod ett IO fel");
};

This topic has been closed for replies.

2 replies

kglad
Community Expert
Community Expert
November 12, 2009

you can append a query string to your aspx call.

November 12, 2009

As kglad said you can always append any URL variable string to your ASPX page path, but that information can be retrieved using tools like FIREBUG in firefox.

So try avoiding that method if you are passing any crucial information like username, password, other personal information, banking information, etc.

November 12, 2009

Use some thing like following:

private function upload()
  {

     var uploadPath:String = "<Enter aspx page path here>";
    var requestFileUpload:URLRequest = new URLRequest(uploadPath);
    var vars:URLVariables = new URLVariables(); //This might help you
    vars.fileName = "<Enter the file name here>";
    vars.XYZ ="<Enter value for XYZ here>";
//Append all your variables in "vars" object to your request

requestFileUpload.data = vars

//Use this to track Upload errors  

fileRef.addEventListener(IOErrorEvent.IO_ERROR, uploadError);
    try
    {
          fileRef.upload(requestFileUpload,"fileContent");
    }
    catch(error:Error)
    {
     trace(error);
    }

     //Use this to track when uploading is complete
    fileRef.addEventListener(Event.COMPLETE, uploadingFinished);
   

     //Use this to receive the response
    fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, uploadCompleteData); //This might help you
   }