Help with REST API, persistent 401 Error

Hello everyone, thank you for this amazing tool.

I have an Orthanc Server up and running, with an OHIF viewer also running using Docker. I have connection between both also running just fine.

Now I want to send images to the Orthanc Server via the REST API.

I am sending the image using a node.js snippet that

  1. First downloads the image from a cloud store, then
  2. Sends the image in binary data (as an ‘arraybuffer’) via a POST call to the Orthanc API.

My orthanc explorer requires a username and password to sign-in, and I have used that to create a basic authorization header, but I keep getting a 401 error from the server.

Below is my code snippet

import axios from “axios”

export default defineComponent({
async run({ steps, $ }) {

function processImage() {
  return new Promise(async (resolve, reject) => {
    try {
      const imageURL = steps.trigger.event.body.imageURL;
      const response = await axios.get(imageURL, {responseType: "arraybuffer"});
      const imageData = response.data;
      const username = <my username>;
      const password = <my password>;
      const token = Buffer.from(`${username}:${password}`).toString('base64');

      const orthancURL = "<my server host and port>/instances";
      const headers = {
        "Content-Type": "application/dicom",
        "Authorization": `Basic ${token}`,
        "Content-Disposition": "attachment; filename=image.dcm"
      };
      const config = {
        headers: headers,
        data: imageData
      };
      const response3 = await axios.post(orthancURL, imageData, config);
      resolve(response3.data);
    } catch (error) {
      reject(error);
    }
  });
}

const result = await processImage();
return result;

},
})

Is there something I am doing wrong? Any help will be much appreciated

Hello,

This looks more like an Axios-related question than an Orthanc-related one.

The Orthanc Book contains examples about how to upload DICOM files using the curl command-line tool. I would suggest you to first give a try to curl, before moving to Axios.

After a quick search on Internet, the following post might help you.

Also, 401 HTTP status code indicates “Forbidden”. Make sure that your Orthanc server has RemoteAccessedAllowed option set to true in its configuration file. But make sure to suitably protect your Orthanc server.

Regards,
Sébastien-

1 Like