Use Filedata Instead of File Attribute to Pass Data

I'm trying to render vtk objects which are send from a webserver directly on the client using XTK without storing them to the disk. According to the XTK Documentation I just have to pass the vtk file as string into X.Mesh.filedata, but it just doesn't display anything when I'm trying to do that.

I want to do something like this:

var data = recieveVTKFileAsStringFromServer();
var r = new X.renderer3D();
r.init();

// create a mesh from a .vtk file
var dataset = new X.mesh();
// dataset.file = 'someFile.vtk';
dataset.filedata = data;

// add the object
r.add(dataset);

// .. and render it
r.render();

When I load the file from the file everything works just fine, setting it using filedata doesn't. Where is my mistake?

1 Answer

I also came up with the similar scenario to load the binary data directly using filedata instead of setting file attribute. I did this by passing dummy name in a file attribute along with actual binary data set in filedata and everything works fine.

var xhr = new XMLHttpRequest();
xhr.open('GET', '/test.nii', true);
xhr.responseType = 'arraybuffer';
xhr.send();
    xhr.onreadystatechange = function (e) {
        if (this.readyState === 4) {
            var r = new X.renderer2D();
            r.container = 'myImg';
            r.orientation = 'Z';
            r.init();
            volume = new X.volume();
            volume.file = "abc.nii";
            volume.filedata = this.response;
            r.add(volume);
            r.render();
        }
    };

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest