0

I have a jquery mobile app (phonegap build). I have a function that will get the uri of an image from the device's photo gallery. I store the uri as a string in local storage so the next time the page is opened, the image displays using the uri. All this works fine (I am not getting the Data-UrI of the image because I don't want to use up the local storage, and I certainly do not want to upload the images to a server due to the app being used in a school (privacy issues). on the device is fine, though. Everything works until I do an update to the app. When the update is installed, the URI to the image changes. How can I get a static URI to the selected picture. Here is the code I use to get the image from the gallery.:

  // JavaScript Document  //Get Picture stuff 
  navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, destinationType:
  destinationType.FILE_URI, sourceType:Camera.PictureSourceType.SAVEDPHOTOALBUM});

   var pictureSource;   // picture source
   var destinationType; // sets the format of returned value 
   pictureSource=navigator.camera.PictureSourceType;
   destinationType=navigator.camera.DestinationType;

   function onPhotoURISuccess(imageURI) {
   // Uncomment to view the image file URI 
     console.log(imageURI);
     localStorage.setItem("piclink", imageURI)

   // Get image handle
    var largeImage = document.getElementById('largeImage');

    // Unhide image elements
     largeImage.style.display = 'block';

    // Show the captured photo
     // The inline CSS rules are used to resize the image
     largeImage.src = imageURI;
     }
     // Called if something bad happens.
    function onFail(message) {alert('Failed because: ' + message);
     }

I should mention that the update I apply does not make any changes to the camera code. All the data stays in localstorage fine, I can see by the console that it saves and calls the URI with no problem, but in the URI path after update, there is a change in the path (a huge string of numbers and dashes). bTW, there is no problem with the Android version. Any help would be greatly appreciated

Cory
  • 1,263
  • 16
  • 31

2 Answers2

1

My understanding is that the imageURI you are saving to localStorage is simply the cdv_* named temporary file as processed by the CDV Camera plugin. As user2603892 correctly pointed out, it appears your concern is the new app location identifier being applied on updates. However, there may be several other issues to consider...the camera plugin sequentially names temp files as picked form the library, or taken as photos. cdv_photo_001.jpg, cdv_photo_002.jpg, etc. This goes on until you do a camera.cleanup(), which removes the cdv_* files.

The plugin stores these files in a /tmp folder off of the application root. Obviously, this would not be copied by iOS on update either.

Sample from Simulator: imageURI = file:///Users/xxxxxxx/Library/Application%20Support/iPhone%20Simulator/7.0.3/Applications/B7B2005C-C116-4BCB-897D-CD46672123C3/tmp/cdv_photo_001.jpg

A suggestion would be to rename and save your file (not the name of the file) to 1) the Documents folder, or 2) an Application Support folder, and then reference it for future use.

Hope this helps.

gro
  • 755
  • 4
  • 7
  • Thank you. When you say "1) the Documents folder, or 2) an Application Support folder, and then reference it for future use" I am not sure I understand the permissions. I thought your app basically has no storage permission. Or, if I store a picture to the users' doc folder, am I basically creating a copy of the image in their roll? Sorry, very new to this. – Cory May 07 '14 at 03:08
  • Your app has storage permission within its sandbox. Perhaps looking into the CDVFile plugin would helpful. Moreover, the Documents folder is the default 'shared' storage on the device, that is also synced with iCloud. And yes, you would be storing a copy of the selected image from their roll, on the device. This way, you will have a fixed URI under your control (eg. update it when you want) and will also allow you to cleanup the camera plugin's tmp folder, if you haven't been doing so, as it can get quite large. – gro May 07 '14 at 12:33
0

I know this is an old post but I thought would share my findings in the hope that it will help somebody else. I am experiencing the same issue on an application which has to store images locally without uploading them to a server. It seems as though the problem is occurring because iTunes installs the update in a new application directory as stated in the iOS App Programming Guide

Files Saved During Application Updates When a user downloads an application update, iTunes installs the update in a new application directory. It then moves the user’s data files from the old installation over to the new application directory before deleting the old installation. Files in the following directories are guaranteed to be preserved during the update process:

<Application_Home>/Documents
<Application_Home>/Library 

Although files in other user directories may also be moved over, you should not rely on them being present after an update.

as discussed Here.

The "huge string of numbers and dashes" you mentioned in your post is the application directory. This changes on each update and therefore the saved URI will be different to the current URI after update.

I am still looking for a work around but have not been able to find anything yet.

Community
  • 1
  • 1
JSS025
  • 51
  • 1
  • 4
  • Thanks for the update--yes, it is kind of a pain, as there is no need for the images my app uses to be uploaded to a server. In fact, because the app is used in schools, we do not want the pics to leave the camera. Hope a work around is found. – Cory May 06 '14 at 00:42