android - Phonegap Build: download image in one of the folders of your app -
android - Phonegap Build: download image in one of the folders of your app -
i able download image if specify path straight
file:///storage/sdcard0/
how can save image 1 of folders in app ? tried this approach set app path doesn't work me.
this using far , works if want save , image sdcard:
class="lang-js prettyprint-override">var filename = "myimage.png";   var filetransfer = new filetransfer();  var uri = encodeuri("http://my.url.to.image/myimage.png");     var filepath = "file:///storage/sdcard0/uploads/myimage.png";  filetransfer.download(     uri,     filepath,     function(entry) {         alert("download complete: " + entry.fullpath);         console.log("download complete: " + entry.fullpath);     },     function(error) {           alert("download error source/target/code:\n" + error.source +" \n||| "+error.target+" \n||| "+error.code);      console.log("download error source/target/code " + error.source+" / "+error.target+" / "+error.code);      }   );     if utilize function:
function getphonegappath() {     'use strict';     var path = window.location.pathname;     var phonegappath = path.substring(0, path.lastindexof('/') + 1);      homecoming phonegappath; }    i /android_asset/www/. how right path app?
the app using angularjs , not bootstrapped in ondeviceready (developer before me made way , changing this beyond me (tried didn't work)).
another question can refer asked here. tried this, this, this , this none worked me. "" fullpath , managed path printed .tourl() , "cdvfile://localhost/persistent". the above download code works if use
filepath = "cdvfile://localhost/persistent/myappid/uploads/myimage.png";    but creates folder /myappid/uploads in /storage/sdcard0 bad again. app needs images
<img src="uploads/myimage.png" alt="myimg"/>    another useful link here offers no help how write pre-created folder of own app.
edit: far i've learned cannot write within own app(read only). that's why tried reference images sdcard
<img src="file:///storage/sdcard0/android/data/com.app.my/cache/myimage.png" alt="myimg"/>    and works! :) unfortunately hardcoded , not since other phones might have different persistent location. if seek
<img src="cdvfile://localhost/persistent/android/data/com.app.my/cache/myimage.png" alt="myimg"/>    this not reference image :/ (it download on storage/sdcard0/android/data/com.app.my/cache/ though)
as far learned cannot write own app (change items within app - /www folder on android).
my solution save images persistent storage (sdcard usually). can path of app's persistent storage these steps:
function ondeviceready() {     console.log('device platform: ' + device.platform);  // returns 'android' or 'ios' instance     window.requestfilesystem(localfilesystem.persistent, 0, gotfs, fail);      cachefoldersubpath = "android/data/com.id.myapp/cache/"; // app's cache folder removed when delete app! (i don't know path should ios devices)   }    then within gotfs success callback
function gotfs(filesystem) {      var nturl = filesystem.root.tonativeurl(); // cdvfile://localhost/persistent/     window.resolvelocalfilesystemurl(nturl+cachefoldersubpath, onresolvesuccess, onresolvefail); }    and in onresolvesuccess
function onresolvesuccess(fileentry){     appcachepath = fileentry.tonativeurl()+"/"; // file:///storage/sdcard0/android/data/com.id.myapp/cache/ in case other androids have storage/emulated/0 or ...      continuecustomexecution(); }    and in continuecustomexecution() can run programme , whatever ... , in case download images appcachepath got earlier. can reference images in src tags our appcachepath+yourimagename.
unfortunately still don't know how download image on ios. error code 1 filetransfer plugin ... (saving file:///var/mobile/applications/my.app.id/documents/). should save somewhere else path when requesting persistent filesystem.
cheers
 android angularjs cordova download phonegap-build 
 
Comments
Post a Comment