UIX - How to read file contents OR get file path to open in custom Python app (and then read_file)

Hi,

I'm trying two things and can't really succeed in either of them. I'm using UIX Dashboards to call my display my own web app in iframe.

1) I would like to read the file contents from M-Files Vault. (I select document, I automatically read the file contents and then I display it to the user - basically how file preview works in M-Files).

- How would I go about this? I know there is a function called ReadTextFile in ICommonFunctions, but it requires a file in the application path, so I would still have to figure out how to download the file to the server application path and then read it and then delete it after I switch to another document. It seems that the file preview function in MFiles works a little differently. Could you do the same with just UIX, or do I need something more? Also not sure if ReadTextFile works on formats that are not .txt

2) I would like to get the file path that my Python script can read.

- When a user opens a path like "mfiles://view/{rest of the file path}" or "Z:/DMS/ID/0/{rest of the file path}" it opens the path to the file just fine, but when external applications try to open the path, it seems they cannot even see it. Of course I would understand that they cant use the first format of the path because that is exclusive to M-Files after installation, but what about the classic "{Disk}:/DMS/etc"? Can I somehow read a document externally?

Thank you in advance for any help. Solving either of those problems would be an absolute win for me.

Dominik

  • Hello Craig,

    I see, I was hoping there would be some function to do these things in UIX too, but it's alright. But this function is great, thank you! I even found some more similar to this is VAF, like GetTextContentsForFile, so I just need to test if it works with my language as well. 

    Now I just need to learn to combine the UIX and VAF together, so hurray to another at least 8 hours of digging through GitHub samples and documentation :D

    I will post my solution here once I figure stuff out, for future references.

    Have a good day!

  • But, so...

    ReadTextFile is for reading files within the application, not files from the vault.  GetTextContentsForFile is for getting the text data, maybe for indexing or similar.  Neither are specifically what you want, which is to read the file contents.

    If the Python script is running on the local computer then you could simply get the local path to the file and pass that to Python.  It should be able to read the data directly from the virtual drive.  If the Python script is running somewhere else then you either need to read the data within Python (i.e. use the COM or REST APIs to download the file), or you need to pass the file data to Python (e.g. by using the method I highlighted that can get the data as a data uri).

    I'm not sure where VAF comes into this.

  • Okay, you've got a point. I was so tangled up in all the code that I thought that I could not read or download a file using UIX, but I was just at the wrong place - I was looking for a function to read/download inside the dashboard itself because I forgot all about the .js file... Sweat smile

    So no VAF, actually did it with UIX and I feel bad for it being this easy.

    if (selectedItems.Count === 1){
    	var objectFileAndVersions = selectedItems.ObjectFiles.Item(1);
    	var fileVer = objectFileAndVersions.ObjectFile.FileVer;
    	var objVer = objectFileAndVersions.ObjVer;
    	
    	// Get file text contents
    	fileContents = shellFrame.ShellUI.Vault.ObjectFileOperations.GetTextContentForFile(objVer, fileVer);
    	
    	// Show dashboard with file contents
    	tab.ShowDashboard("MyDashboard", fileContents);
    	//tab.ShowDashboard("MyDashboard", selectedItems);
    	tab.visible = true;
    }

    Thanks for help, I might still use the DownloadFileAsDataURIEx method later, but now for testing purposes the GetTextContentForFile method is enough.