Search code examples
apache-flexsqliteairsavefilereference

Saving a file in Flex Air


I'm trying to copy my SQLite file that is used in my Air app to user's selected directory using

var fileSaveDest:FileReference = new FileReference();
fileSaveDest.save(dbWorkedFile,'Inventory.DB');

dbWorkedFile is a File

dbWorkedFile = File.documentsDirectory.resolvePath("Inventory.db");

I tried this but the saved file isn't a valid SQLite file.

Also, I was wondering whether it's possible to embed SQLite to Air? If so how can I import and export the database?

Many thanks


Solution

  • In the end I couldn't get FileReference.save() to work so I go with the regular File's browseForSave()

    dbWorkedFile.addEventListener(Event.SELECT, savingDatabase);
    dbWorkedFile.browseForSave('Specify save location');
    
    private function savingDatabase(event:Event):void
    {
        var selectedFile:File = File(event.target);
        //To ensure the file is still loaded
        dbWorkedFile = File.applicationStorageDirectory.resolvePath("Inventory.db");
        dbWorkedFile.copyTo(selectedFile, true);
    }