Custom Widget - mx.data.getDocumentUrl for offline app retrieve wrong url.

1
Hello Im trying to retrieve url for System.FileDocument that is stored locally on device after sync. Im calling function: mx.data.getDocumentUrl(guid, changedDate, false)  with guid of that particular object, on result i receive following:   I receive from mx.data.getDocumentUrl 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?
asked
2 answers
1

Hi,

The mx.data.getDocumentUrl() 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 mx.data.getDocumentUrl(), 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 = mx.data.getDocumentUrl("<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() { 
			cordova.plugins.fileOpener2.open(
				newFilePath,
				mimeType,
				{
					error : function(errorMsg){ console.error(errorMsg); },
					success : function(){}
				}
			);
		}, function() { console.error('Copying Unsuccessful '); });
	}, function (errmessage) {console.error(errmessage)});
}, function (errmessage) {console.error(errmessage)});

 

answered
0

Hi Pavels,

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

answered