PDA

View Full Version : Reading path to file with FileReference?


fx.barrett
02-06-2009, 05:24 PM
A fast Flex question ( not AIR ). Is it possible to get the exact path to a file from Flex when browsing for it with the help of a FileReference object's browse() method ? If not, then how should I handle this the best way (because obviously, I'll need to get a server-side script to somehow read the file's path and then pass it back to Flex but how will I pass the file to my server-side script so it will know what to look for ? ) ?

fx.barrett
02-06-2009, 06:36 PM
I think I know how... I'll be back if I get it to work.

senocular
02-06-2009, 06:41 PM
You shouldn't be able to get the path of the file from a FileReference - for security reasons. However, when you post it to the server, the server will save the file bits to a temporary directory (usually) and the server script handling that will be able to move it, or provide a server-based path if needed.

fx.barrett
02-06-2009, 07:24 PM
Hi Sen, yeah I was thinking the same thing. Good to know that "things theoretically are looking good" :) Thanks for the reply.

fx.barrett
02-08-2009, 09:01 AM
Ok, I'm back and I'm stuck. What I'm trying to do is send a list of files from Flex 3 to an ASP.NET web service ( written in C# ) and attach the those files to an e-mail. Essentially, the app is a contact form that has an "attach file" feature where someone can attach one or more files to the mail he will be sending...

Since I'm not pro at ASP.NET, I recently started "playing around" with ASP.NET I have no idea in what format to send the files, who to send the file's path so I can use the Attachment class from ASP.NET, loop trough the list of file paths and attach each file to the e-mail.

Can anyone point me in a dirrection ? I've been sufring the net all day for something that would put me on the right track but with no luck... After reading up on some ASP.NET mail sender apps, I finally figgured out how to add multiple attachments to my mail, but since ASP.NET can actually read the local path of the file when browsing for it from an ASP.NET / HTML contact form things are much easier then doing the same thing in Flex... I'm not even sure if I would need to send a FileReferenceList or a collection of another type and what kind of object would that translate into ASP.NET ( what type would the param be that is waiting for that list ) ? And once I can send it, then how would I read the paths so I can actually attach it ?

So, any help from an experienced ASP.NET developer or someone who already dealth with stuff like this would really be appreciated. Thanks.

fx.barrett
02-09-2009, 03:37 AM
No one ?

I thought of a more "brutal" idea: to upload the files first to the server and since I'll then know their exact path/name I can simply pass an array of strings ( paths ) to my ASP.NET web service and attach them.. once it's done, I could delete them from the server... but personally, I don't think this would be such a great solution and I would leave it as "my last option".

I'd really like to know how to pass a FileReferenceList ( or what's needed ) to my ASP.NET web service and loop trough it to attach each file to my e-mail.

Any adieas / suggestions would really be welcome...

senocular
02-09-2009, 02:28 PM
You might want to post the ASP portion of this question in the server-side forum.

vipin
09-22-2011, 06:25 AM
import mx.events.FileEvent;
private var openFile:File = new File()

private function openBrowseWindow():void{
openFile.addEventListener(Event.SELECT, onOpenFileComplete);
openFile.browse();
}

private function onOpenFileComplete(event:Event):void{
trace("event: "+event.target.nativePath);
}