0

How to perform file read write operation on server in flex web application? Please guide.

Your help would be appreciated.

Vivek
  • 663
  • 2
  • 13
  • 40
  • duplicate? http://stackoverflow.com/questions/2300850/writing-to-a-file-in-as3-flash-develop – duedl0r May 02 '11 at 11:58
  • 1
    Hi, my requirement is little bit different, i want to save my file data on server not on my local system and also i do not want to give him browser file option. – Vivek May 02 '11 at 12:10

2 Answers2

5

Well it all depends on. Fileread operation is possible in a web application, but filewrite has to be solved with a server side language, like php.

Generally, for reading you can use URLStream, this reads a file into a stream. The easiest usage is:

var ldr:URLStream = new URLStream();
ldr.addEventListener("complete", ldrDone);
ldr.load(new URLRequest(URL_OF_YOUR_FILE));

function ldrDone(evt:*):void
{
     //store the file in a bytearray
     var bytes:ByteArray = new ByteArray();
     evt.target.readBytes(bytes);
     trace(bytes);
}

To write files, use php or whatever script. How to write this and what to include in the code really depend on your project.

For flash-related file reading (like loading a swf, or supported image formats, mostly jpg, gif, png natively), use the Loader class.

For text files and xmls, use the URLLoader class.

If you have more questions, feel free to ask.

anemgyenge
  • 2,220
  • 12
  • 13
  • Hi sir, If i am recording sound in Flex web application then the data store on server or on local system? Basically i want to create a application which can record user voice notes. So in application process when user recorded his voice note then i need to save it on server [in file or in database]. I am able to record user voice note but i am not able to finding out solution for saving that data on server. Please guide. Many thanks for your support – Vivek May 03 '11 at 10:33
  • How do you "store" the voicenote? Do you use a premade library for it? If your application works without a living internet connection, then I guess the answer for your first question is that the data is "stored" on the local system. Though, I guess it is "stored" rather in the memory. So, can you tell how do you store it? Is it a ByteArray? – anemgyenge May 04 '11 at 08:37
2

Depends completely on your backend server technology. PHP, Java, ASP.NET? Either way you use the same server side documentation tutorial on your server side as handling a file upload. On the flex side FileReference.upload does the trick.

See: http://livedocs.adobe.com/flex/3/html/help.html?content=17_Networking_and_communications_7.html

http://www.flex888.com/296/9-flex-file-upload-examples-visited.html

http://www.adobe.com/devnet/flex/articles/file_upload.html

JTtheGeek
  • 1,707
  • 14
  • 17