Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to read a dicom file from network stream #1698

Open
cocosip opened this issue Dec 8, 2023 · 3 comments
Open

How to read a dicom file from network stream #1698

cocosip opened this issue Dec 8, 2023 · 3 comments
Labels

Comments

@cocosip
Copy link

cocosip commented Dec 8, 2023

When i try to open a dicom from network stream, it will get some error, here is my code

var stream = await client.GetStreamAsync("http://xxxxx/1.dcm");
var dicomfile = await DicomFile.OpenAsync(stream, FileReadOption.SkipLargeTags);

it will throw an exception : NotSupportedException: Specified method is not supported

Does fo-dicom supports opening a DICOM directly from a network stream ? I saw "UnseekableStreamByteSource" in the source code, which seems to be used to read DICOM data from network streams ?

@cocosip cocosip added the new label Dec 8, 2023
@gofal
Copy link
Contributor

gofal commented Dec 21, 2023

Agree, unseekable streams are already implemented in development branch. Could you verify, when using the latest development-code, that opening the file from networkstream actually works?

@cocosip
Copy link
Author

cocosip commented Dec 21, 2023

gree, unseekable streams are already implemented in development branch. Could you verify, when using the latest development-code, that opening the file from networkstream actually works?

I use HttpClient.GetStreamAsync(url) to get the stream, but the stream not support get the length。So the stream returned by the GetStreamAsync method cannot be used directly to open a DICOM file。

@gofal
Copy link
Contributor

gofal commented Dec 21, 2023

Ah ja, the UnseekableStreamByteSource assumes, that seeking is not supported. But this stream not even supports the Length property, which is even worse.
The quick fix is to download into a memorystream and then to parse using fo-dicom. The long fix, is to implement another version of ByteSource that uses streams without using Length. But to tell you the truth, this class internallly will have no other chance than to just download the data piecewise, buffer it into a memorystream and then do the parsing from that memorystream. That is also how UnseekableStreamByteSource is doing it.
So it will not be faster or less memory consuming because in both ways it has to download all the data, and the parsing will only be finished when all the data is ready downloaded. It will mainly be syntactic sugar because it saves you 1 line of code and newbie users are not surprised about a NotSupportedException when opening a DicomFile from a HttpResponseStream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants