Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi,

I want to convert file into bytes..... i am using this for file upload in which i am taking bytes of the file and calling my upload handler which is in c sharp and uploading it.... can anyone help.....
Posted

I think you can do something like this to fetch the byte array

XML
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="loadFile()">

    <mx:Script>
        <![CDATA[

                private var loadedFile:ByteArray;

                private function loadFile():void
                {
                        var request:URLRequest = new URLRequest("http://test.enunciato.org/sample.pdf");
                        var urlLoader:URLLoader = new URLLoader(request);

                        urlLoader.addEventListener(Event.COMPLETE, onURLLoaderComplete);
                        urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
                        urlLoader.load(request);
                }

                private function onURLLoaderComplete(event:Event):void
                {
                        loadedFile = event.target.data;
                }

                private function saveLoadedFile():void
                {
                        var file:FileReference = new FileReference();
                        file.save(loadedFile, "SampleDoc.PDF");
                }

        ]]>
    </mx:Script>

    <mx:Button label="Save Image" horizontalCenter="0" verticalCenter="0" click="saveLoadedFile()" />

</mx:Application>
 
Share this answer
 
take a look here, there was just another question about the same topic:

How to convert pdf file into byte array,retrieve byte array into pdf file in flex?[^]
 
Share this answer
 
I have used following code and worked fine for me ....and it will work when flash player 10 is installed and settings are changed as per below site:


SQL
FileRef.addEventListener(Event.SELECT,FileSelect);
    FileRef.addEventListener(Event.COMPLETE,onFileComplete);




C#
var filedata:ByteArray=new ByteArray();
        public function onFileComplete(event : Event) : void
             {
                         FileRef = event.currentTarget as FileReference;
                         filedata=FileRef.data;
                         var data:ByteArray = new ByteArray();
                         FileRef.data.readBytes(data,0,FileRef.data.length);
                                                       //  byteCheckUpload.writeLocation(data, FileRef.name)
                                                              }



C#
private function FileSelect(evt:Event):void
   {
         FileRef.load();
         Txt_FileName.text=evt.currentTarget.name;
    }

http://opensource.adobe.com/wiki/display/flexsdk/Targeting+Flash+Player+10[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900