How to fetch file object of vaulted File with JS so we can later read the file content?

Hi community,

does anybody a way to read the file content of existing Files in the Vault (mainly xml data) with Javascript?

For example we have an CAD item with an xml file in the property native_file.  With an button click I want to read the filecontent and stream the result to another system. (I know that the xml files are not the typical content of the CAD ItemType, I just abuse this ItemType for my current test :-) ). 

I know that we can use fetchFileProperty to download files to the client. In addition there seems to be an additional 3rd parameter where we can define if we really want to download the file (Standard Mode), or only get the File item (Dry Mode). But none of these two modes will return the native FileObject needed for the FileReader.

I tried the following code from a regular Form button:

var fileObject = document.thisItem.fetchFileProperty("native_file", "C:\\Temp", 1);

This variant will return the file item. Is there any way to get the file object itself with JS?

Another possible solution would be to use C# for this task. This way we could download the file temporary to the server and then ready the file content there. But maybe it´s possible to avoid this additional download?

Thanks for any help!

  • Hi Angela!

    Didn't you yourself answer a similar question in this blog post? It would mean relying on the Aras REST API instead of using JS IOM, though.
    Or did I misunderstand the question?

    Cheers,

    C

  • Hi Cogres,

    you wouldn´t believe how often I google for a specific Innovator topic just to figure out that I already asked or answered the same question some time ago .Blush

    In this case you are right with your linked forum topic. The use case is quite similar. But I don´t want to stream a file from an external location. I just want to access a file, that is already available in Innovators own file vault. So I don´t think it´s very efficient to use a REST connection just to access data that the user already can access.

    This is my latest idea:

    var fileId = document.thisItem.getProperty("native_file");
    var fileDownloadUrl = aras.IomInnovator.getFileUrl(fileId , aras.Enums.UrlType.SecurityToken);
    var request = new XMLHttpRequest();
    request.open('GET', fileDownloadUrl, true);
    request.send(null);
    request.onreadystatechange = function () {
        if (request.readyState === 4 && request.status === 200) {
           var type = request.getResponseHeader('Content-Type');
           if (type.indexOf("text") !== 1) {
                alert(request.responseText);
           }
        }
    };

    In this sample I create a temporary file download link and then read the file content from the link. But I am not sure if this one is a recommended way to solve this task.

    Would be happy if somebody knows a more straight and lean variant.

  • Hi Angela,

    I see! I didn't mean it in an accusatory way whatsoever, just thought it was a little bit funny to find that you answered a very similar question a few years back :D.

    If what was written in the blog post we talked about still holds true, there is no IOM way of doing what you want to do. So we either have to REST it up (which is a little weird to do from within an already active Aras session, I agree), or do something similar to what you have suggested.
    Of course, I cannot really comment on the overall data security of doing it in either of those ways in your particular setup. But I cannot think of another clever way to do what you want to be doing either.

    Cheers,

    C

  • Hi Cogres,

    At no time did I find your post accusatory -  nobody was more surprised than me  Laughing.

    I am also not sure about the security and performance aspect of my current solution. But in my use case this is not a big problem, cause the Method is mainly used for occasional data validation. It´s not a Method that is used on a daily basis by all users, so I think it should do the job.

    Angela