Custom Widget - for offline app retrieve wrong url.

Hello Im trying to retrieve url for System.FileDocument that is stored locally on device after sync. Im calling function:, changedDate, false)  with guid of that particular object, on result i receive following:   I receive from function: file:///storage/emulated/0/Android/data/io.mxapps.offlinemobile101_sandbox/files/files/documents/15481123719086281@1559915525155?1559915525156 Actual URL: file:///storage/emulated/0/Android/data/io.mxapps.offlinemobile101_sandbox/files/files/documents/15481123719086281@1559723283285   So as you can see file names are different. And receiving URL from function the second part of file name after @ is always different comparing to previous. How to receive proper document URL?
2 answers


The will return correct directory and the file name that is based on input parameters. Mendix is naming files that are synchronized as [GUID]@[ChangedDate]. As soon as you know it and you combine it with the fact that at least directory is correct when using, you are able to get the url of a file.

Some working example of how do I open PDF file assuming FileDocument is my file to open:

var fileName = FileDocument.getGuid()+'@'+FileDocument.get('changedDate');
//I need to copy the file with correct extension, otherwise, even when mimetype is defined, Adnroid won't open the file
var newFileName = FileDocument.get('Name');
//I'm using split param to get correct directory
var filesUrl ="<split>");
var filesUrlParts = filesUrl.split("<split>");

var filePath = filesUrlParts[0]+fileName;
var newFilePath = filesUrlParts[0]+newFileName;

var mimeType = FileDocument.get('MimeType');
window.resolveLocalFileSystemURL(filePath, function (fileEntry) {
	window.resolveLocalFileSystemURL(filesUrlParts[0],function (directory) {                  
		fileEntry.copyTo(directory, newFileName, function() {
					error : function(errorMsg){ console.error(errorMsg); },
					success : function(){}
		}, function() { console.error('Copying Unsuccessful '); });
	}, function (errmessage) {console.error(errmessage)});
}, function (errmessage) {console.error(errmessage)});



Hi Pavels,

Did you ever find out how to receive the proper document URL?