Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to upload file to Orthanc server from C# application

I am trying to upload a DICOM file to local Orthanc server but I get the error that:

Unknown Tag & Data (2d2d,6664) larger (1647393075) than remaining bytes (76) in file, premature end of stream
E0424 16:02:20.786940 FromDcmtkBridge.cpp:1925] Cannot parse an invalid DICOM file (size: 84 bytes)

I have wrote the following code to upload the file on the server:

DicomFile dicomfile = new DicomFile(dataset);
dicomfile.Save("dicomfile.dcm");

////finally uploading the file to Orthanc
String dcm = File.ReadAllText("./test9signedLimited.dcm");

HttpClient client = new HttpClient();

client.DefaultRequestHeaders.Add("ContentType", "multipart/form-data");
HttpContent content = new MultipartFormDataContent();

content.Headers.ContentType= new MediaTypeHeaderValue("multipart/form-data");

var response = client.PostAsync("http://localhost.:18888/instances", content).Result;

response.EnsureSuccessStatusCode();
var r = response.Content.ReadAsStringAsync().Result;

Note I have tried to upload the same file using POSTMAN and it was successfully uploaded there.

Thanks for your help in advance.

like image 975
ComputerGenius Avatar asked Nov 25 '25 10:11

ComputerGenius


1 Answers

Not knowing anything about C#, but I see two problems in the code at the moment.

  1. You read in the DICOM file from disk, but I don't see any code to actually attach the DICOM data to the POST request. It seems, that You are posting an empty request with only headers.
  2. You use File.ReadAllText to read the DICOM file from disk, which returns a String. This does not seem right, since DICOM is a binary format and converting to it to a string is more than likely to break it. You more likely need a byte array with the DICOM data to attach to the POST request.
like image 156
Tarmo R Avatar answered Nov 26 '25 23:11

Tarmo R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!