I am currently trying to use an ipyvuetify FileInput field. My expectation was that if I were to define v_model, that I would be then able to read the selected file from filefield via the v_model attribute.
import ipyvuetify as v
def file_selected(x,y,z):
print(filefield.v_model) # value is {}
print(x) # value is FileInput(placeholder='Select an file...', v_model={})
print(y) # value is 'change'
print(z) # value is {}
filefield = v.FileInput(v_model='', placeholder = 'Select an file...')
filefield.on_event('change', file_selected)
What I find when I execute this code however, is that filefield.v_model is an empty dictionary. There are three arguments passed to the 'change' event, but none of them seem to contain 'what' file has been selected. How do you get the selected file from a ipyvuetify FileInput?
I had a similar issue. The default method of
ipyvuetify.FileInput
doesn't seem to work. You have to useipyvuetify.extra.FileInput
. Here is an example which is close to what you are trying:Or if you just want the file name after the dialog is finished, use:
filename = fi.get_files()[0]['name']
Credit to: github.com/widgetti/ipyvuetify/issues/50