簡體   English   中英

無法從C#應用程序將文件上傳到Orthanc服務器

[英]Unable to upload file to Orthanc server from C# application

我正在嘗試將DICOM文件上傳到本地Orthanc服務器,但出現以下錯誤:

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)

我編寫了以下代碼以將文件上傳到服務器上:

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;

注意我嘗試使用POSTMAN上傳相同的文件,並且已成功上傳到那里。

感謝您的幫助。

對C#一無所知,但目前我在代碼中看到兩個問題。

  1. 您從磁盤讀取了DICOM文件,但是我看不到任何將DICOM數據附加到POST請求的代碼。 看來,您正在發布一個僅包含標題的空請求。
  2. 您使用File.ReadAllText從磁盤讀取DICOM文件,該文件返回String 這似乎不對,因為DICOM是二進制格式,將其轉換為字符串很有可能會破壞它。 您很可能需要一個帶有DICOM數據的字節數組來附加到POST請求。

盡管此答案不涵蓋C#解決方案,但是您可以使用python選項來幫助您。 Orthanc服務器 [1]具有將DICOM圖像發送到服務器的解決方案。 說明如下。

python ImportDicomFiles.py localhost 8042 ~/DICOM/

[1] Jodogne,S.,2018年。用於醫學成像的Orthanc生態系統。 Journal of Digital Imaging,31(3),第341-352頁。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM