I created a Cordova application that retrieves images from a server and saves them on an iPad. However, when you try to display images in the application, images are not loaded. One example of such a file path might be:
file:///var/mobile/Containers/data/Application/FC87E925-9753-4D9F-AE27-54FCF9B0451E/Documents/-media-3405-company.png
However, when checking the variable cordova.file.applicationDirectory I find another way, for example. (note that the UUID is different, although I check both variables in the same run)
file:///var/containers/Bundle/Application/D8266D08-18A4-4293-B78A-B4597FC0C6B8/salesApp.app/
According to the documentation, the correct path should be: (however this doesn't work either)
file:///var/mobile/Applications/UUID/Documents/-media-3405-company.png
Here is the code that I use to upload images that are correctly saved on the device
const downloadFile = (url, fileName, callback) => { window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, (fs) => { fs.root.getFile(fileName, { create: true, exclusive: false }, (fileEntry) => { const fileURL = fileEntry.toURL() const fileTransfer = new FileTransfer() fileTransfer.download( url, fileURL, (entry) => { const file = entry.toURL() // <--- HERE content.pushObject('Downloaded ' + entry + ' (' + fileName + ') ' + file) callback(file) }, (error) => { content.pushObject('error ' + error.code + '(' + fileName + ')') if (error.code === FileTransferError.CONNECTION_ERR) { downloadFile(url, fileName) // Try again } else { decrement(url) // Ignore this file } } ) }, (error) => { alert(2) }) }, () => { alert(3) }) }
Update: checking the value for cordova.file.documentsDirectory , I found that it returns a path similar to: file:///var/mobile/Containers/Data/Application/{UUID}/Documents/ .
Update: The following code will return two different UUIDs:
alert(cordova.file.applicationDirectory); // file:///var/containers/Bundle/Application/54E0F914-C45B-4B8F-9067-C13AF1967760/salesApp.app/ alert(cordova.file.documentsDirectory); // file:///var/mobile/Containers/Data/Application/73806E90-90B4-488C-A68A-2715C3627489/Documents/
When checking the path for entry.toURL() I get the same UUIDs as those returned in cordova.file.documentsDirectory .