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)});
Hi Pavels,
Did you ever find out how to receive the proper document URL?