Skip to main content
Participating Frequently
September 18, 2009
Question

Write Bytes server side with File class

  • September 18, 2009
  • 1 reply
  • 1084 views

Hi there,

Does anyone knows if it's possible to write some bytes received from an AIR or Flex client in a server side file using the File class ? I have been trying for hours without any result.

My goal is to store on the server side a swf file sended by a client in a ByateArray.
Here is the code I have ended with, assuming that myfile.swf alreadey exists on the server prior to the code execution, and is at the right place, and that pBytes is a ByteArray received from the client which contains a swf file :


function writeFile( pBytes )

{

     var myFile = new File( "myFile.swf" );

     if( myFile.open( "binary", "write" ) )
     {

            for( var i = 0; i < pBytes.length; i++ )

            {
                 myFile.writeByte(  pBytes );

                 myFile.seek(  i );

            }

     }

     myFile.flush();
     myFile.close();

}

Before using the for loop I tried writeAll() and write() methods without success. FMS won't record the bytes in the file and, an error is raised :

Sending error message: C:\Program Files\Adobe\Flash Media Server 3.5\applications\_convexe2009\main.asc: line 114: File operation writeByte failed.

Does anyone have any idea of what's happening here ?
I would really appreciate any help on this, because this is driving me nuts !
Txhs

    This topic has been closed for replies.

    1 reply

    Participating Frequently
    November 4, 2009

    Similar kind of discussion going on this thread :

    check it may help you

    http://askmeflash.com/qdetail/299/error-when-writing-binary-file

    Participating Frequently
    November 4, 2009

    Hi Inderjit, thx for your answer. I ended with a PHP solution...