1 Reply Latest reply on Aug 17, 2010 5:04 AM by Neobox75

    Copying an image from a URL to local storage?


      Hey I'm trying to write a bit of code that checks if there is a local version of the image then use it, else copy the image from the server. Basically caching images. Could anyone help me with my code please?



                          var imgPath = api_url+'images/'+media[x].image; //set to the live version on the server by default

                          //check for a cached version of the image
                          var cachedImage = air.File.applicationStorageDirectory.resolvePath(media[x].image);
                          if(cachedImage.exists) {

                               //set the image path to the cached image
                              imgPath = cachedImage; //is this right?
                          else { //no local version of the image found

                               //copy the file from the server to the storage directory, any example code?


                               imgPath = ???  //then set the imgPath        

                          //show the image

                          div.style.background = '#000 url('+imgPath+') center center no-repeat';