Search code examples
filesoaptitaniumbase64titanium-mobile

Titanium save files from stream


I have a streamer from server(SOAP) with different type of files, and i what seve it in physical storage. I try this code but i only create file with my string.

api.getFile(function(fileString) {

        var original = 'Appcelerator';
        var decoded = Ti.Utils.base64decode(fileString);

        var Settings = Titanium.Filesystem.getFile(Titanium.Filesystem.tempDirectory, 'Settings');
        var newFile = Titanium.Filesystem.getFile(Settings.nativePath, 'Settings.pdf');
        newFile.createFile(decoded);
      // Ti.API.info('newfile: '+newFile.read());    
    }); 
}
}

Solution

  • try this one..

     var original = 'Appcelerator';
     var decoded = Ti.Utils.base64decode(fileString);
    
     var Settings = Titanium.Filesystem.getFile(Titanium.Filesystem.tempDirectory, 'Settings');
     Settings.createDirectory();
     var newFile = Titanium.Filesystem.getFile(Settings.nativePath, 'Settings.pdf');
     newFile.write(decoded);