Reputation: 9828
I have built 1 app that has to run on iOS, android and Windows Phone. all work fine apart from iOS. My app takes a photo using the camera, resizes that image and saves the image.
On iOS, these images were being saved into the tmp directory of the application, which was being deleted, so now i save the images into the Documents folder.
I then save the path to this image into my sqlite database. On my html page, i reference the file using the url, such as
var/mobile/application/GUID-HERE/Documents/imageName.jpg
Now it seems that when i rebuild my application in xCode, the application guid is changed, so all my file references that have been previously saved, are now invalid.
So
OR
Upvotes: 1
Views: 4163
Reputation: 2427
Use the toInternalURL()
property of the File plugin. After you save your image, you can get a local url without that GUID and save that to your database instead. The url has this format
cdvfile://localhost/persistent/path/to/file
An example: (mostly from file-transfer docs. requires file and file-transfer plugins)
resolveLocalFileSystemURL(cordova.file.documentsDirectory, function success(entry) {
download(entry.toInternalURL() + "image.jpg");
});
var download = function(localUrl) {
var fileTransfer = new FileTransfer();
var uri = encodeURI("https://cordova.apache.org/images/cordova_bot.png");
fileTransfer.download(
uri,
localUrl,
function(entry) {
document.body.innerHTML = entry.toInternalURL();
var img = document.createElement("img");
img.setAttribute('src', entry.toInternalURL());
document.body.appendChild(img);
},
function(error) {
console.log("error code" + error.code);
},
false,
{
headers: {
"Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
}
}
);
}
Upvotes: 1