ipywidgets icon indicating copy to clipboard operation
ipywidgets copied to clipboard

Document workarounds for file upload size limit

Open cosmoscalibur opened this issue 5 years ago • 34 comments

Is there a size limit property in FileUpload widget or a restriction for big files? Using a FileUpload with a file of 6MB, I can access to data and value fields, but when I choose a file of 10MB counter changes but data and value fields are empty.

  • python=3.6.7
  • notebook=6.0.0
  • ipywidgets=7.5.0

Using conda-forge channel (Anaconda) for installation.

cosmoscalibur avatar Jul 29 '19 21:07 cosmoscalibur

In Tornado, websocket messages have a limit of 10MB, IIRC. That may be what you are hitting.

jasongrout avatar Jul 29 '19 21:07 jasongrout

Is there an error in the js or server side?

jasongrout avatar Jul 29 '19 21:07 jasongrout

In Tornado, websocket messages have a limit of 10MB, IIRC. That may be what you are hitting.

Is there a workaround? We need files about 20MB. When upload files web console shows:

Connection lost, reconnecting in 1 seconds. default.js:144     _onWSClose default.js:144

cosmoscalibur avatar Jul 29 '19 22:07 cosmoscalibur

See https://github.com/jupyter/notebook/issues/3468 for more background

jasongrout avatar Jul 29 '19 23:07 jasongrout

For future reference:

Example to limit size in 100 MB.
Create config file

jupyter notebook --generate-config

Edit (uncomment) the following line in jupyter_notebook_config.py (generated file) and change the value (desired size in MB * 1024 * 1024):

c.NotebookApp.tornado_settings = {"websocket_max_message_size": 100 * 1024 * 1024}

Launch notebook with --config parameter pointing to config file:

jupyter notebook --config="jupyter_notebook_config.py" your_notebook.ipynb

cosmoscalibur avatar Jul 30 '19 14:07 cosmoscalibur

Thanks for following up with a workaround!

jasongrout avatar Jul 30 '19 15:07 jasongrout

Do you think this is a common enough issue that we should note it in the docs?

jasongrout avatar Jul 30 '19 16:07 jasongrout

Yes, because with the popularity of Jupyter notebooks and now, the support of tools as voila to create web apps from notebooks, we can think in support upload of big files for analytics. For example, an image easily is bigger than 10 MB and a short video without codec applied also is bigger than 10 MB.
Also, for clarity, this is a limitation in the functionality of the widgets, and this is not mentioned.

cosmoscalibur avatar Jul 30 '19 16:07 cosmoscalibur

Great. To be clear, this is a limitation of Tornado which impacts widgets. Would you mind writing up some text we could put in the docs around the file upload widget? Something that would have helped you a few days ago to understand the situation and work around the tornado limitation?

jasongrout avatar Jul 30 '19 16:07 jasongrout

Or we could adapt what you wrote above, of course. Where would you have expected to find this note? In the widget list by the file upload widget? https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html#File-Upload

jasongrout avatar Jul 30 '19 17:07 jasongrout

I think that FileUpload is clear because is the common scenario where easily increase the size of messages but I don't know if other widget could be affected (HTML rendering with load of images and video, or image widget?). And, of course, you can adapt the text of my comment.

cosmoscalibur avatar Jul 30 '19 18:07 cosmoscalibur

Thanks. I'm reopening this issue then, as an issue for adding documentation about the workaround above to the widget list, just by the file upload widget.

jasongrout avatar Jul 31 '19 01:07 jasongrout

Yes I'm getting same problem when uploading HDF files (needed for analysis), which are really big in size!

Launch notebook with --config parameter pointing to config file: jupyter notebook --config="jupyter_notebook_config.py" your_notebook.ipynb

@cosmoscalibur @jasongrout Actually I am creating a Voila app accessible via mybinder.org so is there a way to ensure that each notebook that user opens, is by default launched with this config parameter?

jaladh-singhal avatar Aug 12 '19 15:08 jaladh-singhal

@cosmoscalibur @jasongrout Actually I am creating a Voila app accessible via mybinder.org so is there a way to ensure that each notebook that user opens, is by default launched with this config parameter?

That is a great question for the voila or mybinder repos.

jasongrout avatar Aug 12 '19 15:08 jasongrout

That is a great question for the voila or mybinder repos.

@jasongrout So do you know how to find answer? What are the relevant people involved with it who can solve it?

jaladh-singhal avatar Aug 12 '19 16:08 jaladh-singhal

I would either ask on the Jupyter discourse (probably better) or ask in an issue on the binderhub repo: https://github.com/jupyterhub/binderhub

jasongrout avatar Aug 12 '19 17:08 jasongrout

Yes I'm getting same problem when uploading HDF files (needed for analysis), which are really big in size!

Launch notebook with --config parameter pointing to config file: jupyter notebook --config="jupyter_notebook_config.py" your_notebook.ipynb

@cosmoscalibur @jasongrout Actually I am creating a Voila app accessible via mybinder.org so is there a way to ensure that each notebook that user opens, is by default launched with this config parameter?

In that case @jaladh-singhal , you need to use a setup.py (use data_files field), postBuild file or dockerfile to specify the copy of the voila.py or jupyter_notebook_config.py in etc/jupyter .

cosmoscalibur avatar Aug 13 '19 01:08 cosmoscalibur

I would either ask on the Jupyter discourse (probably better) or ask in an issue on the binderhub repo: https://github.com/jupyterhub/binderhub

@jasongrout Thanks alot. Please let me know if you find a standard solution, other than this wonderful workaround we now know.

jaladh-singhal avatar Aug 13 '19 12:08 jaladh-singhal

In that case @jaladh-singhal , you need to use a setup.py (use data_files field), postBuild file or dockerfile to specify the copy of the voila.py or jupyter_notebook_config.py in etc/jupyter .

@cosmoscalibur Thanks I'll try it out and let you know if it works or not. Just to be clear, where I should copy this jupyter_notebook_config.py in etc/jupyter, under its root or inside any subdirectory? My directory tree of etc/jupyter is as follows:

├── jupyter_notebook_config.d
│   └── voila.json
├── jupyter_server_config.d
│   └── voila.json
└── nbconfig
    ├── common.json
    ├── edit.json
    ├── notebook.d
    │   ├── bqplot.json
    │   ├── voila.json
    │   └── widgetsnbextension.json
    ├── notebook.json
    ├── terminal.json
    └── tree.json

jaladh-singhal avatar Aug 13 '19 13:08 jaladh-singhal

@jaladh-singhal etc/jupyter/voila.py . Using voila, you need to change c.NotebookApp.tornado_settings for voila.

cosmoscalibur avatar Aug 15 '19 01:08 cosmoscalibur

re: binderhub, if you want to have this config setting for all jupyter notebook servers launched off of your binder deployment (instead of having each individual repo create a jupyter notebook config using postBuild), you can add it using extraConfig in your config.yaml:

hub:
    extraConfig:
     myConfig: |
      tornado_settings_values = {
        "websocket_max_message_size": 104857600
        }
      c.KubeSpawner.args = [
        f'--NotebookApp.tornado_settings={tornado_settings_values}'
        ]

The trick is that you have to pass the tornado settings dictionary in a f-string, otherwise you'll run into an error as KubeSpawner will pass the arg as a string entirely (tornado_settings requires a dictionary)

eexwhyzee avatar Feb 07 '20 18:02 eexwhyzee

Doesn't work for me so far, but I'm also getting no errors. I'm running Jupyter from a conda environment, would that change anything? Is there any other way to change the file size limitation from tornado?

EDIT: Having a different conda environment / using the base Kernel makes no difference to me.

Kladderadatasch avatar Apr 28 '20 12:04 Kladderadatasch

I can upload files up to about 150 Kb. Even using the torando modification in the configuration file via

"websocket_max_message_size": 100 * 1024 * 1024

Has someone any ideas on that?

Kladderadatasch avatar May 03 '20 21:05 Kladderadatasch

Just generating the file jupyter_notebook_config.py with the modification mentioned above and leaving it inside the folder .jupyter does not work for me.

"websocket_max_message_size": 100 * 1024 * 1024

What is working for me is to copy the config file to the same folder as the notebook I working on. Then I launch the notebook using the config file.

jupyter notebook --config="jupyter_notebook_config.py" my_notebook.ipynb

I hope it helps

Cheers

danjmp avatar Jul 10 '20 15:07 danjmp

Is it (technically) possible to modify the javascript widget in some way to chunk the files and send it over the connection? For example as multiple 5MB messages instead of all the files in one go. I am guessing the issue occurs when the front end view tries to set the value on the model and it's all in one go?

https://github.com/jupyter-widgets/ipywidgets/blob/6be18d9b75353f7b4a1c328c6ea06d8959f978f6/packages/controls/src/widget_upload.ts#L98

mrinalraghupathi avatar Aug 24 '20 02:08 mrinalraghupathi

Is it (technically) possible to modify the javascript widget in some way to chunk the files and send it over the connection? For example as multiple 5MB messages instead of all the files in one go. I am guessing the issue occurs when the front end view tries to set the value on the model and it's all in one go?

Yes and no. It's of course technically possible to split up a file into multiple parts and create multiple messages to stay under the 10mb limit. However, the ipywidgets protocol currently assumes each message is a self-contained state change, so we'd need to do something nontrivial changing the ipywidgets protocol to allow accumulating the results of multiple messages.

jasongrout avatar Jan 27 '21 23:01 jasongrout

Just generating the file jupyter_notebook_config.py with the modification mentioned above and leaving it inside the folder .jupyter does not work for me.

"websocket_max_message_size": 100 * 1024 * 1024

What is working for me is to copy the config file to the same folder as the notebook I working on. Then I launch the notebook using the config file.

jupyter notebook --config="jupyter_notebook_config.py" my_notebook.ipynb

I hope it helps

Cheers

Hi @danjmp, I tried to use your trick with voilà but sadly the widget still only accepts 10MB.

Is there any other workaround to make this work within a voilà app?

@jasongrout any thoughts ?

Alexboiboi avatar Feb 18 '21 22:02 Alexboiboi

Hi @jasongrout,

what about the "chunks" approach used by @mariobuikhuizen in ipyvuetify in https://github.com/mariobuikhuizen/ipyvuetify/blob/master/ipyvuetify/extra/file_input.py

would there be a way to implement it directly in ipywidgets?

also open issue : mariobuikhuizen/ipyvuetify#50

Alexboiboi avatar Sep 09 '21 19:09 Alexboiboi

I would either ask on the Jupyter discourse (probably better) or ask in an issue on the binderhub repo: https://github.com/jupyterhub/binderhub

@jasongrout Thanks alot. Please let me know if you find a standard solution, other than this wonderful workaround we now know.

Hi there and @jaladh-singhal Were you able to solve the max upload size issue , specially in voila?

Jeannotisintheplace avatar Apr 08 '22 11:04 Jeannotisintheplace

I would either ask on the Jupyter discourse (probably better) or ask in an issue on the binderhub repo: https://github.com/jupyterhub/binderhub

@jasongrout Thanks alot. Please let me know if you find a standard solution, other than this wonderful workaround we now know.

Hi there and @jaladh-singhal Were you able to solve the max upload size issue , specially in voila?

@Jeannotisintheplace sorry I couldn't try because requirements of the project changed.

jaladh-singhal avatar Apr 08 '22 12:04 jaladh-singhal