2

I have a router like as below:

Router.route("/public/dicom/:dataid/:filename", function () {
    var filePath = this.params.dataid + "/" + this.params.filename;

    var basePath = process.env.HOME;
    var filename = basePath + "/public/dicom/" + filePath;
    //        var filename = path.normalize(path.join(basePath, "public/dicom/" + filePath));
    //console.log("+==================", filename)
    var res = this.response;
    if (!fs.existsSync(filename) ||
        !fs.statSync(filename).isFile()) {
        //console.log("==========================ERROR")
        res.writeHead(404, { 'Content-Type': 'text/html' });
        res.end('404: no such asset: ' + this.params.filename);
        return;
    }
    var data = fs.readFileSync(filename);
    res.writeHead(200, { 'Content-Type': "application/octet-stream", "charset": "binary" });
    res.write(data);
    res.end();
}, { where: "server" });

Just read content of DICOM file and return client. Response like as response data

In client site, I want to use response data as arrayBuffer data. Please help me!

PS: When I try use response data, I got some error like Uncaught TypeError: Cannot read property 'byteLength' of null

 var dataOfPapaya = new Uint8Array(response.content);
 console.log('dataOfPapaya', dataOfPapaya.byteLength);
 var params = [];

 // Configuration
 params['binaryImages'] = [dataOfPapaya];
 params['kioskMode'] = true;
 params['showControls'] = false;
 params["showOrientation"] = true;
 params["radiological"] = true;

 papaya.Container.startPapaya();
 papaya.Container.resetViewer(0, params);

I use papayajs to view DICOM file: https://github.com/rii-mango/Papaya

devcfz
  • 31
  • 4

1 Answers1

0

You need to use ArrayBuffer. I can recreate the error you're seeing when using Uint8Array.

 var dataOfPapaya = response.content;
 var params = [];
 params['binaryImages'] = [dataOfPapaya];

See here for an example using ArrayBuffer.

martinez314
  • 12,162
  • 5
  • 36
  • 63