{"id":7980,"date":"2012-09-23T23:18:05","date_gmt":"2012-09-23T17:48:05","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=7980"},"modified":"2016-12-16T11:41:35","modified_gmt":"2016-12-16T06:11:35","slug":"download-and-store-external-files-to-mobile-in-phonegap","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/download-and-store-external-files-to-mobile-in-phonegap\/","title":{"rendered":"Download and Store External Files to Mobile in PhoneGap"},"content":{"rendered":"<p>In my current PhoneGap project, I was required to give the offline support of the application. I had to store all the external files on the device and refer the file from local device path. This required a thorough knowledge of storing external files on a\u00a0device using PhoneGap.<br \/>\nPhoneGap comes with very handy FileTransfer API which allows a\u00a0developer to download any file from URL and store it on the device. For storage,\u00a0we needed the complete\u00a0path where we wanted to store the file. Let&#8217;s take an example.<\/p>\n<p>[java]<br \/>\nfunction storeIntelligrapeLogo(){<br \/>\n  var url = &quot;http:\/\/www.intelligrape.com\/images\/logo.png&quot;; \/\/ image url<br \/>\n  window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {<br \/>\n      var imagePath = fs.root.fullPath + &quot;\/logo.png&quot;; \/\/ full file path<br \/>\n      var fileTransfer = new FileTransfer();<br \/>\n      fileTransfer.download(url, imagePath, function (entry) {<br \/>\n               console.log(entry.fullPath); \/\/ entry is fileEntry object<br \/>\n      }, function (error) {<br \/>\n               console.log(&quot;Some error&quot;);<br \/>\n      });<br \/>\n   })<br \/>\n}<br \/>\n[\/java]<\/p>\n<p>Using above code, we were able to download the file and its stored in <strong>&#8220;\/Users\/intelligrape\/Library\/Application Support\/iPhone Simulator\/5.0\/Applications\/CF2A9018-49B9-4DE6-91FC-EA76CB435FC8\/Documents\/logo.png&#8221;<\/strong> on my system (As I run the code on simulator).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my current PhoneGap project, I was required to give the offline support of the application. I had to store all the external files on the device and refer the file from local device path. This required a thorough knowledge of storing external files on a\u00a0device using PhoneGap. PhoneGap comes with very handy FileTransfer API [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":7},"categories":[518,1772,1],"tags":[1009,1011,921,1010],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/7980"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=7980"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/7980\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=7980"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=7980"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=7980"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}