Accessing upload file in <input> inside a div model

Hello,

I am sending large files to the server with FileInput model so the websocket is automatically closed. I tried to inscrease the websocket max message size but it is not working. Then I am trying something new.

I created the following div model:
div= Div(
text=‘’,
)
and a submit button: submit = Button(
label = “Submit file”
)

Is there a way to access the file upload with via a CustomJS on the submit button or something ?

Thanks in advance.

How big is your file?

I had the same problem with a file of about 30 MB, using the option --websocket-max-message-size solved the problem.

For example, I started my app with following command:

bokeh serve --show file_name.py --websocket-max-message-size 1000000000

If this doesn’t help, please provide a minimal reproducible example for us to investigate it.

1 Like

The file is 9Mo so not so large but still enough to make the websocket closed.
To add context to my problem, the bokeh serve is deployed on a openshift v4 container.
Regarding the --websocket-max-message-size I tried but it is sill not working…

Well this is strange because the standard value is already 20 MB.
See help text if you write bokeh serve --help:

--websocket-max-message-size BYTES
         Set the Tornado websocket_max_message_size value (default: 20MB)

And my experience is that 9 Mo (≈ 9 MB) should work.
Your problem may have something to do with OpenShift.

To test if your problem is due to Bokeh, try to run following code directly (not on OpenShift):

from bokeh.io import curdoc
from bokeh.models import FileInput

file_input = FileInput(width=600)
def file_callback(attr, old, new):
    print(f"-> New file loaded, beginning with: {new[:20]}...")

file_input.on_change('value', file_callback)

curdoc().add_root(file_input)

Run with: bokeh serve --show file_name.py
Then try to upload a file. You will see in the logs if it works or not.

Increasing the file size, you will see that somewhere between 10 and 20 MB this doesn’t work anymore, the message WebSocket connection closed: code=None, reason=None is shown.
Then, using the option “–websocket-max-message-size 1000000000”, files of more than 100 MB should be loadable.

Also, I think I didn’t right understand how you really try to catch the file in your code.
You say in the text that you use FileInput model but in your code I only see a Div and a Button but no FileInput.
For further help, please provide a minimal reproducible example.

1 Like

Thanks for the answer.

Loading a file via a FileInput model works in local (in my computer) but does not when I deploy the app on OpenShift. That is why I tried another solution, to create a html input within a div and upload the file with it. But I got the same problem, it works in local and while deployed in Openshift, the websocket is closed. And I tried to use the option “–websocket-max-message-size 1000000000”

Your example is the same code that I created, it works in local but not in a Openshift container.

In the end, it looks like the –websocket-max-message-size param is not taken into account, even if the logs indicates it

Literally the only Bokeh does with this value is pass it on to the corresponding underlying Tornado API:

So, while it’s not impossible that there is a bug in Tornado, considering things works locally, it seems much more likely to me that this is a limitation or configuration issue with Openshift (obviously Bokeh has no control over that). I’d suggest you try to find a support forum for Openshift that might be able to shed more light on things from the Openshift side of things (I have zero experience with it, and cannot offer any guidance about it).

Hello, I resolved the issue, it was on openshift side. Thanks for your answers

That’s great to hear @Matthbt can you summarize the problem and solution (or link to a discussion) for the benefit of any future users who might come upon this?

To summarize, I had problem to upload a large file with FileInput model in my app deployed in Openshift. It was working fine in local so I searched in the configuration parameters of Openshift and find the one responsible for the max websocket size. Increasing it worked.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.