Uploading instance in react js

I am trying to upload an instance in my react js application.
This works but i don’t get a response body returned to the request.

const formData = new FormData();
formData.append('file', file);
const response = await axios.post('https://my-orthanc-server/instances', formData, {
        headers: {
          'Content-Type': 'application/octet-stream',
        },
})

But this doesn’t(when i convert file to binary)

const binaryData = await file.arrayBuffer();
const response = await axios.post('https://my-orthanc-server/instances', binaryData, {
        headers: {
          'Content-Type': 'application/octet-stream',
        },
});

When i use the fetch API, i get an err TypeError: Failed to fetch. I have my orthanc server running behind nginx.

Please what do i need to do to upload an instance from the client side, and get the response body of the successful request

In order to get a response, you need to upload it as a multi part form. I suspect your headers are incorrect. Multipart Bodies | Axios Docs

HTH.

James

Thanks James.
I have reviewed my headers and it seem correct according to the documentation.

Hello,

This looks like an issue related to same-origin policy, doesn’t it? By default, a JavaScript application is not allowed to make a call to another server such as https://my-orthanc-server/, except if some dedicated mechanism such as CORS is setup. Carefully check out the logs of your browser in developer mode.

Regards,
Sébastien-

1 Like

Thanks guys :pray:.
I’ve been able to resolve this by changing the 'Content-Type': 'multipart/form-data'