Reputation: 1
I'm trying to make a web application in jupyter notebook using voila but it's my first time and I can't get it to work.
My goal is to upload an image, save it to a predefined folder and display it in the app.
So far, i can create the upload widget like this:
import ipywidgets as ipw
uploader = ipw.FileUpload()
display(uploader)
and it's ok, but when i want to acces the value or content to save it, i get this error:
uploader.value
{}
uploader.content
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Input In [21], in <cell line: 1>()
----> 1 uploader.content
AttributeError: 'FileUpload' object has no attribute 'content'
Any help or recommendation will be highly appreciated. Thanks
Upvotes: 0
Views: 498
Reputation: 9790
I prefer to observe the change upon file upload. An example will probably illustrate it best.
To see it in operation go here and press 'launch binder
'. When the sessions spins up, select 'streamlined 3D scatter plot in Voila interface' from the list of available demonstrations.
Based on here.
The code for that is here.
There is equivalent of that running in the notebook if you choose '3D scatter plot using data in a file and Voila interface' from the list of available demonstrations.
Based on here the way you are approaching it, it seems:
"Once the user has picked a file with the file selector, the contents of the file will be available in a bytes object, under the .data property of the FileUpload object." - SOURCE
Maybe you can try accessing that?
See also https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html#file-upload
Upvotes: 0