Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Sqlite Flex
hi,
i m wondering to upload file from flex to sqlite database and again need to retrieve from database to flex.can anyone help me how to do this?
Posted 14-Mar-12 21:58pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

There are several good articles and tutorials to be found: try searching the easy way[^]
 
I also recommend to by a book, that topic will be covered in nearly all books.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

<fx:Script>
        <![CDATA[
import flash.filesystem.File;
            import flash.system.Capabilities;
            import flash.utils.ByteArray;
import mx.utils.Base64Decoder;
            import mx.utils.Base64Encoder;
 
public var fnamearr:Array=new Array();
            private var loadedFile:ByteArray;
            public var byte:String;
            public var bytesarr:Array=new Array();
            public var p:int;
 
/*browse button function*/
 
public function browse_file(eve:MouseEvent):void{
                file1 = File.documentsDirectory;
                file1.addEventListener(Event.SELECT, handleSelectFile);
                file1.browseForOpen("Select Picture");
 
            }
            public function handleSelectFile(event:Event):void
            {
                if(os=="Win" ){
                    file_name.text = event.target.nativePath;
                }
                else if(os=="Mac"|| os=="Lin"){
                    file_name.text = event.target.url;
                }
                fnamearr.push(event.target.name);
                Alert.show(event.target.name);
                var request:URLRequest = new URLRequest(file_name.text);
                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;
                var encoder:Base64Encoder=new Base64Encoder();
                encoder.encodeBytes(loadedFile);
                byte=encoder.toString();
                bytesarr.push(byte);
                //byte=encoder.encode(loadedFile);
                Alert.show('==>'+file_name.text);
 
            }
/*finally store bytesarr (array),fnamearr(filename array) into sqlite database*/
 

// save in sqlite database
public function saveLoadedFile():void
            {
 
                for(var j:int=0;j<bytesarr.length;j++){
                    if(bytesarr[j].length!=0 && bytesarr[j]!='' ){
                        dbStatement=new SQLStatement();
                        dbStatement.sqlConnection=exampleDB;
                        dbStatement.text="INSERT INTO cmr_patient_files (patient_id,file,filename) VALUES (:recordId,:byteArray,:recordNote)";
                        dbStatement.parameters[":recordNote"] = fnamearr[j];
                        dbStatement.parameters[":byteArray"] = bytesarr[j];
                        dbStatement.parameters[":recordId"] = spat_id;
                        dbStatement.execute();
                    }
                }}
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 5,170
1 DamithSL 4,357
2 Maciej Los 3,750
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,851


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 12 Apr 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100