Kitware/itk-vtk-viewer

Cannot find IO for nrrd file

idoRosen25 opened this issue ยท 14 comments

im trying to display an .nrrd file in the viewer from S3.
i have a link for downloading the file.

when i download and copy the file to my project it load without any issues, how ever loading it directly from the s3 link throws an error from the piepline.worker that it cannot find IO for the file.

any idea or suggestions for the issue? (im trying to find a solution that will not require downloading the file to my server every time i want to display it)

The file extention, .nrrd, is used to find the right "IO" flow. Lets try having your S3 url end in /filename.nrrd

i am using the url as such but still doesnt load.. i can even see that it found the right filename.. but still cannot recognize the needed IO.. how can i debug or see some errors on that? i cant seem to intercept it..

Does the URL end in .nrrd?
Yes: https://dandiarchive.s3.amazonaws.com/3d313fc2-0204-496d-bfa1-5c90951ee640.nrrd
No: https://dandiarchive.s3.amazonaws.com/3d313fc2-0204-496d-bfa1-5c90951ee640

For debugging: here is the place passing a URL to 'createViewer' will reach:

imageHref.split('/').slice(-1)[0]

See it grabbing the last part of the URL after the / and treating it as the "filename"?

my URL is composed as such: http://<domain>/fileName.nrrd?<authDataForS3> (since its a protected library).
this url should download the file from S3 (which works and downloads locally on client) but using it directly doesn't find the needed IO.
how can i overcome this issue? (preferably without changing the URL or server logic)

P.S. : im using seaweedFS (should work the same as AWS s3)

Does the URL end in .nrrd? Yes: https://dandiarchive.s3.amazonaws.com/3d313fc2-0204-496d-bfa1-5c90951ee640.nrrd No: https://dandiarchive.s3.amazonaws.com/3d313fc2-0204-496d-bfa1-5c90951ee640

For debugging: here is the place passing a URL to 'createViewer' will reach:

imageHref.split('/').slice(-1)[0]

See it grabbing the last part of the URL after the / and treating it as the "filename"?

Hi there :)

So can we replace this parsing with something more robust like

image.pathname.split('/').slice(-1)[0]

that would take care of any query parameters and so on? (assuming image is an instance of URL)

P.S. maybe even use at(-1) instead of slice(-1)[0] (depends on compatibility I guess)?

image.pathname.split('/').at(-1) looks great!

Do you have the time to open a PR?

image.pathname.split('/').at(-1) looks great!

Do you have the time to open a PR?

Will do!

image.pathname.split('/').at(-1) looks great!

Do you have the time to open a PR?

I kind of went a bit further, really hope I didn't go overboard and that function is not public API :)

the current split in toMultiSpatialImage is correct (getting the value after the last / in the URL). however since i have query params to authenticate, it cannot find the file name correctly (getting a string as follows: fileName.nrrd?<queryParams>. adding .split("?")[0] fixed it and it now displays correctly.
however, it seems that some functions in the itkVtkViewer.js are getting not a function error (i found this issue in event handlers for scroll, click and drag events).
any idea why it happened?

@idoRosen25 Errors may be cuz .split("?")[0] passes the more than just the "filename" (like protocol, domain...). Jemennius PR should work if I understand your URL. Post your full url with the names changed? What does this print for you

cont url = new URL( [ your full image url here ] )
console.log(url.pathname.split('/').pop())

the logic now and the one that @Jmennius suggested have the same effect.
the logic alway return the string after the last / in the url. e.g. url is domain/dir1/dir2/filename and i get back the filename in both cases.
in our case the url is www.domain.com/dir1/dir2/filename.nrrd?queryParams so i get filename.nrrd?queryParams as a result which is the reason for getting no IO found error.

i added another split on top of the logic (either one since they act the same) to split the result by ? with gives me the following array: [filename.nrrd,queryparams] (or only the first of the elements if no ? exists.

the logic now should be url.split("/").slice(-1)[0].split("?")[0] (for @Jmennius fix suggestion it will be url.pathname.split('/').pop().split("?")[0]) and it will fix cases where the url does not end in filename.nrrd but contain some queryParams as well

pathname removes the query params.

const url = new URL('http://www.domain.com/dir1/dir2/filename.nrrd?asdf=kkdkkd&qwer=poiu')
console.log(url.pathname) // prints '/dir1/dir2/filename.nrrd'

๐ŸŽ‰ This issue has been resolved in version 14.14.0 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€

@idoRosen25 Please give the latest master a spin and feel free to re-open this issue.