# How to load nifti file from web browser link?

**URL:** <https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664>\
**Category:** Development\
**Created:** [July 13, 2021, 12:44pm UTC](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664 "2021-07-13T12:44:28Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [November 3, 2021, 6:48pm UTC](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664/21 "2021-11-03T18:48:11Z")

</div>

> [@lassoan](#):
>
> @pieper What do you think? I know that we could just use SlicerWeb extension as is, but it seems more like a prototyping extension, contains lots of hardcoded, project-specific, experimental things and so it is quite complex.

Yes, the SlicerWeb project has a lot of experimental parts and is not complete. I’ve been thinking for quite a while that it should be refactored and simplified. That said it does work well and could be the basis for this ‘singleton app’ feature and others. It probably looks more complex than it really is because I was trying to figure out how it needed to work while developing this version. The actual core is not that big and most of the rest would be better as plugins.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 3, 2021, 7:38pm UTC](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664/22 "2021-11-03T19:38:22Z")

</div>

Considering that “singleton app” is a core feature, needed in many use cases, it would be much better to have it in the Slicer core.

What do you think about bringing base classes and maybe some stable request handlers (such as opening of an URL) to the Slicer core and leave the experimental and project-specific features in SlicerWeb and other extensions?

Or we could clean up Slicer Web and move out experimental things to other extension(s).

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [November 3, 2021, 7:53pm UTC](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664/23 "2021-11-03T19:53:38Z")

</div>

Yes, there’s a very small set of code in SlicerWeb that would enable the essential functionality. I agree it would be better in the core than in an extension so that people could rely on it being available. Let me try look into that and try a PR. It’s really just the one `WebServer` scripted module.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 3, 2021, 8:02pm UTC](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664/24 "2021-11-03T20:02:25Z")

</div>

Sounds great!

We could consider adding two request handlers to the Slicer core: one for opening an URL and another one for executing Python command and return the output. By default the server would be disabled, so it would not be a security risk.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [November 3, 2021, 8:22pm UTC](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664/25 "2021-11-03T20:22:05Z")

</div>

Yes, I already have a `repl` endpoint in the web server that accepts python code and returns the result. The first time the request is received the user gets a dialog to accept or not (along with an ‘always accept’ checkbox). We may want to make a separate preference for allowing this endpoint since it seems more risky than some of the others (but it’s super powerful too!).

It is definitely important to consider security implications before using this. I also recently added a `certfile` option to support https.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 4, 2021, 7:48pm UTC](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664/26 "2021-11-04T19:48:12Z")

</div>

@OLIVERFCHEN

I’ve pushed the DICOMweb import enhancements, which will be available in the Slicer Preview Release from tomorrow. Improvements include:

- fine-grained progress reporting during downloading of each series (not just when a series download is completed)
- avoid re-downloading of content already in the local DICOM database
- select loaded content in the DICOM browser when import is finished
- improved error handling (errors are displayed in a popup window)

While @pieper takes care of moving core parts of the web server to the Slicer core, you can already write a Python script that starts Slicer (if not started already) and uses the [SlicerWeb extension](https://github.com/pieper/SlicerWeb/) to make it load an image via a web request.

---

<div class="post-metadata">

**Author:** ![OLIVERFCHEN](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/oliverfchen/32/13069_2.png) [@OLIVERFCHEN](https://discourse.slicer.org/u/OLIVERFCHEN)\
**Post date:** [November 10, 2021, 1:45pm UTC](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664/27 "2021-11-10T13:45:06Z")

</div>

@lassoan  
I download the newest slicer 4.13.0-2021-11-9, I tested using the URL to open the slicer, but it took much longer time than before to download the data. Wonder if this is only me?  
Confirmed when the file already existed in the slicer, it will not download again.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 10, 2021, 4:15pm UTC](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664/28 "2021-11-10T16:15:57Z")

</div>

Good catch, thanks for reporting this. The download time got increased by the combination of detailed logging and increased progress reporting. On a test case, download time increased from 150sec to 244sec. I’ve updated the importer to only report warnings and errors during series download, which cut the download time to 68sec.

The [fix](https://github.com/Slicer/Slicer/commit/a4d51a19f2ce0a553a2b4cc9fa8bade0781df568) will be included in the Slicer Preview Releases from tomorrow but you can apply the change to your local installation now (just modification of a single .py file).

---

<div class="post-metadata">

**Author:** ![OLIVERFCHEN](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/oliverfchen/32/13069_2.png) [@OLIVERFCHEN](https://discourse.slicer.org/u/OLIVERFCHEN)\
**Post date:** [November 18, 2021, 1:42am UTC](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664/29 "2021-11-18T01:42:31Z")

</div>

I’ve been waiting for the update about the “singleton app”, any news?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 18, 2021, 3:52am UTC](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664/30 "2021-11-18T03:52:00Z")

</div>

The pull request to integrate the WebServer module into Slicer core is still under review:

> <https://github.com/Slicer/Slicer/pull/5999>
>
> Code imported from Steve Pieper's development repository.
> 
> https://github.com/…pieper/SlicerWeb

You don’t need to wait for this to be merged. You can get the WebServer module files from that branch and copy them into your `<SlicerInstallFolder>lib\Slicer-4.13\qt-scripted-modules` folder then start Slicer and open the WebServer module. It starts the web server automatically. Instead of the GUI, you can also start Slicer and start the WebServer module from the command line.

After this, you can make Slicer open a file by sending a command via Slicer’s REST API. For example, you can open a file by running these few lines from any Python environment:

```python
import requests
import sys
filename=sys.argv[-1].replace('\\','/')
port = 2016
requests.post(url=f'http://localhost:{port}/slicer/repl', data='slicer.app.loadFiles([\''+filename+'\'])', timeout=15)

```

You can use Slicer’s Python interpreter to run this (unlike the full Slicer application, it starts up in a second) by copying the above script into a new `ShowInSlicer` folder: `<SlicerInstallFolder>/bin/Python/ShowInSlicer/ __main__.py` (this creates a Python module that can be referred to by name instead of a full path). After this, you can execute this command in the terminal:

```auto
PythonSlicer.exe -m ShowInSlicer c:\tmp\CTChest.nrrd

```

It will open the specified file in the running Slicer instance.

After the WebServer module will be integrated into the Slicer core, I’ll add a Python script like the one above to the Slicer core, so it will not be necessary to mess with copying files. It could also make sense to add detection of the server to the script: if the server is not running then the script could start Slicer.

---

<div class="post-metadata">

**Author:** ![kmordhwaj](https://avatars.discourse-cdn.com/v4/letter/k/5f8ce5/32.png) [@kmordhwaj](https://discourse.slicer.org/u/kmordhwaj)\
**Post date:** [January 19, 2023, 9:28am UTC](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664/31 "2023-01-19T09:28:16Z")

</div>

Can we upload more than 50 nifti files at a time with a link or can we upload a folder of these much nifti files through script in 3d slicer?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [January 19, 2023, 4:47pm UTC](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664/32 "2023-01-19T16:47:53Z")

</div>

Yes, you can do this.

---

<div class="post-metadata">

**Author:** ![kmordhwaj](https://avatars.discourse-cdn.com/v4/letter/k/5f8ce5/32.png) [@kmordhwaj](https://discourse.slicer.org/u/kmordhwaj)\
**Post date:** [January 20, 2023, 4:31am UTC](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664/33 "2023-01-20T04:31:01Z")

</div>

How to do that @pieper ? Is there is any script available? or we just need to pass a link with the prams which have the downloadable folder of these much files. Because I think we can’t pass it in link as folder is not considered as downloadable file.  
please help.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [January 20, 2023, 12:57pm UTC](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664/34 "2023-01-20T12:57:03Z")

</div>

The scripts @lassoan posted just above your post gives the formula, just repeat it for all your volumes. One note: the WebServer module is now is the Slicer release, so no need for special installation. Also the `repl` endpoint has been renamed `exec`. What this `exec` endpoint allows is for external programs (e.g. python or shell scripts) to invoke the execution of python code in the Slicer application just as if it had been typed in the python console of the application or initiated by other GUI actions in the application. It’s a very powerful feature so you should be able to accomplish whatever you are trying to do.

If this isn’t clear, please post what specifically you are trying to accomplish and what tools you are using and maybe we can make more concrete suggestions.

---

<div class="post-metadata">

**Author:** ![kmordhwaj](https://avatars.discourse-cdn.com/v4/letter/k/5f8ce5/32.png) [@kmordhwaj](https://discourse.slicer.org/u/kmordhwaj)\
**Post date:** [January 20, 2023, 1:02pm UTC](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664/35 "2023-01-20T13:02:21Z")

</div>

Thank you @pieper . I will give it a try.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 20, 2023, 1:27pm UTC](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664/36 "2023-01-20T13:27:38Z")

</div>

There have been even more improvements since this thread was started: you can use the [slicerio Python](https://pypi.org/project/slicerio/0.1.8/) package to conveniently open an image in Slicer bya simple Python call. slicerio launches Slicer with web server interface enabled and opens the file.

For example, after installing slicerio Python package, run this in any local Python environment to open an image in Slicer:

```auto
import slicerio.server
slicerio.server.file_load("https://github.com/rbumm/SlicerLungCTAnalyzer/releases/download/SampleData/LungCTAnalyzerChestCT.nrrd", slicer_executable="path/to/Slicer.exe")

```

See more information and examples [here](https://github.com/lassoan/slicerio#view-files-in-3d-slicer).

---

<div class="post-metadata">

**Author:** ![kmordhwaj](https://avatars.discourse-cdn.com/v4/letter/k/5f8ce5/32.png) [@kmordhwaj](https://discourse.slicer.org/u/kmordhwaj)\
**Post date:** [January 20, 2023, 1:32pm UTC](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664/37 "2023-01-20T13:32:07Z")

</div>

Thanks @lassoan. It is a great updated feature. But this is for a one file, can I open slicer 3d with a link which contains a folder of the files? Like how we are importing a single file or a directory in 3d slicer.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 20, 2023, 1:37pm UTC](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664/38 "2023-01-20T13:37:01Z")

</div>

What is your end goal? Quickly view the 50 files one by one? Or view more (or all) at once?

Are those files in a local directory or a web server somewhere? If you show them one by one, how do you decide on the order?

Does the user need to do anything with them? For example, view one by one and approve or flag each? Maybe edit some segmentation results and submit the revised segmentation to a server?

---

<div class="post-metadata">

**Author:** ![kmordhwaj](https://avatars.discourse-cdn.com/v4/letter/k/5f8ce5/32.png) [@kmordhwaj](https://discourse.slicer.org/u/kmordhwaj)\
**Post date:** [January 20, 2023, 1:46pm UTC](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664/39 "2023-01-20T13:46:34Z")

</div>

Thanks for replying @lassoan , My folder which contains 50 NIFTI files is in my local repository. I mean in my app in cloud as .zip file.  
when user click “label in slicer” then it will download zip and the zip will be extracted and will be in local downloads folder. (so can say the folder is in local directory).  
There is a feature in the 3d slicer where I can take a file or a directory so I am trying to open 3d slicer and the directory should load.  
I can open and place a file by cli command in subprocess, but giving error while putting folder in path.

The user want to label it and edit it to get obj file.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 20, 2023, 2:24pm UTC](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664/40 "2023-01-20T14:24:51Z")

</div>

This use case is often implemented by simply sharing a dropbox or onedrive folder. The user drag-and-drops an image into the Slicer application window, segments it, and saves the result. Since segmentation typically takes tens of minutes, the 10-20 second task of loading and saving data usually does not justify doing any Python scripting to speed up things.

A more modern approach is to use MONAILabel for this. You can start a single MONAILabel server and many users can connect to it using the MONAILabel extension in 3D Slicer. MONAILabel automatically provides an image by a single click; the user can then segment the image (optionally MONAILabel may provide a default AI segmentation) and finally the user uploads the segmentation result by a single click.

[Previous page](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664.md?page=1)

[Next page](https://discourse.slicer.org/t/how-to-load-nifti-file-from-web-browser-link/18664.md?page=3)
