Cordoba iOS application directory and file URL are different (UUID problem)

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 .

+5
source share
1 answer

When you state that “images are not loading”, then you must provide the code used to download the images. The code you provided is image loading and it works great.

As you did not specify the code used to download the images, I tried two things, and both of them worked

  • Open the InAppBrowser file. I installed the cordova-plug-inappbrowser and opened the file as follows: window.open(file,'_blank');
  • Display file in img tag. I created the img tag in my index.html <img id="downloaded" src=""/> and in my callback I assigned the file received in src document.getElementById("downloaded").src = file;

Both of them worked.

So, you must specify your code used to upload images, because the problem may be there.

The path you get at boot is fine.

You get different UUIDs because the documents are out of date. Prior to Xcode 6 / iOS8, the application sandbox contained a Bundle container and a data container inside the same folder (the one mentioned in the documentation with a common UUID), but since Xcode 6 / iOS8 application files (Bundle container) are in the path and application data files are in another (data container).

But that should not be a problem for you.

An answer that talks about file structure changes

+3
source

Source: https://habr.com/ru/post/1268874/


All Articles