sencha touch - How to offer files for download? -
i have problem. in sencha touch application have list items .pdf, .png, ... if user taps on 1 of them file should download on mobile device. how can this? have no idea :-)
thanks help.
you can use phonegap file api download files, if using sencha touch 2.3 or above follow bellow steps.
install phonegap in sencha project executing following command @ project root , command creates phonegap folder inside project root.
sencha phonegap init
you need install 2 phonegap plugins work file api executing 2 following commands inside phonegap folder.
$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file.git
$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer.git
now can start working file api in sencha touch , can follow below code used 1 of project.
if want download file, first need read device file system , using file system can download files.
getfilesystem : function(){ var me =this; ext.viewport.mask({ xtype: 'loadmask', message: 'downloading files..' }); var extfs = ext.create("ext.device.filesystem.cordova"); extfs.requestfilesystem({ type: window.persistent, size: 1024 * 1024, success: function(fsys) { window.filesys = fsys; ext.viewport.unmask(); me.filedownload("myfolder/filename.png","http://someurl"); }, failure: function(error){ alert(error); ext.viewport.unmask(); } }); }
i passing filelocation(location want store file inside phone) & url in above function.
filedownload: function(filelocation,url){ ext.viewport.mask({ xtype: 'loadmask', message: 'downloading files..' }); var me = this; var fsys = window.filesys if(fsys){ var file = ext.create('ext.device.filesystem.fileentry', fsys.fs.root.tourl() + filelocation, fsys); file.download({ source: url, success: function(entry){ ext.msg.alert('success', 'image downloaded'); ext.viewport.unmask(); }, failure: function(error){ ext.msg.alert('error', 'download failed'); ext.viewport.unmask(); } }); } }
now can see image @ internalmemorycard/myfolder/filename.png
sencha docs
ext.device.filesystem.fileentry
if using sencha touch 2.2 or below change instead of using sencha class need directly use phonegap api.
for reading file system & file download follow phonegap documentation.
Comments
Post a Comment