Improve create-dicom endpoint error message

Hello! I have a suggestion about the error messages of the /tools/create-dicom endpoint.

I am experimenting with a “dicomizer” feature in my application where I allow users to upload JPEG/PNG images. It works gracefully in the browser, but when we tried via mobile, we had a very weird error inside Orthanc:

org.springframework.web.client.HttpClientErrorException$NotFound: 404 Not Found: [{
“HttpError” : “Not Found”,
“HttpStatus” : 404,
“Message” : “Unknown resource”,
“Method” : “POST”,
“OrthancError” : “Unknown resource”,
“OrthancStatus” : 17,
“Uri” : “/tools/create-dicom”
}]

I spent quite some time trying to understand what was going on, as a 404 made me think my application had some issue with requests from mobile devices. It turns out the issue was the fact that users were trying to upload .jpg files, where a lot of images are in this .jpg format instead of .jpeg, and I was wrongly setting image/jpg as the content type of the encoded files to send to Orthanc.

My suggestion is: since a 404 in this case is very misleading, can we improve the error message, e.g to say that the MIME type is wrong? I believe mobile image uploading is a very common case for dicomization

Hi Diego,

Indeed, it seems we can improve the error report here !
Could you provide us with a sample file and curl command to reproduce the issue ? That would help us prepare the work.

Thanks

Alain

Hi Alain. Here is an example:

Let’s say we have a file request.json:

{
“Tags”: {
“X”: “Y”
},
“Content”: [
“data:image/png;base64,WIOJisoaiasIIAJIiosOIADIODoi=”,
“data:image/jpeg;base64,WIOJisoaiasIIAJIiosOIADIODoi=”,
“data:image/jpg;base64,WIOJisoaiasIIAJIiosOIADIODoi=”
],
}

Then we post it with curl

curl -v -H “Content-Type: application/json” -X POST --data @request.json http://localhost:8042/tools/create-dicom

You receive a 404 because image/jpg is an invalid MIME type. I got this problem because images in phones have .jpg extension, and I was relying on this file extension to construct the MIME type.

A quarta-feira, 9 de novembro de 2022 à(s) 10:23:02 UTC, a…@orthanc.team escreveu:

Hi Diego,

Could you provide an exact and complete curl command that generates your error ?

I have attached the one I spent some time to recreate based on your message and the command is successful no matter if I use “image/jpeg” or “image/jpg”.

Best regards,

Alain.

test-create-dicom-jpeg.txt (63.4 KB)

Hi Diego,

One of our customers had the same issue as you today and I could finally reproduce the problem. I was not able to reproduce it because I was using the old payload structure for this route.

The fix is here: https://hg.orthanc-server.com/orthanc/rev/b89833d7ce22

Best Regards,

Alain.

Hello,

Note however that there is no such thing as a MIME type “image/jpg” (only “image/jpeg” does exists):
https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types

Consequently, I have submitted the following change to avoid considering “image/jpg” as MIME-compliant in the source code of Orthanc, while preserving compatibility with Alain’s original modification:
https://hg.orthanc-server.com/orthanc/rev/a3c3f13368ea

Regards,

Sébastien-

Hi Alain/Sébastien!

Supporting image/jpg, but without considering it a MIME type is a great solution. Thanks!

A quarta-feira, 23 de novembro de 2022 à(s) 13:29:16 UTC, s.jo...@gmail.com escreveu: