In [ ]:
import os,sys
sys.path.insert(0, os.path.abspath('..'))
from hublib.ui import FileUpload

In [ ]:
# called when all files finish uploading
def done_cb(w, name):
    # Do something with the files here...
    # We just print their names
    print("%s uploaded" % name)
    
    # reset clears and re-enables the widget for more uploads
    # You may want to do this somewhere else, depending on your GUI
    w.reset()

Single File Uploads


In [ ]:
# this will allow you to select a single file to be uploaded
f = FileUpload("Really Interesting File", 
               "This is a description that appears when the mouse hovers over the name.",
               dir='tmpdir',
               cb=done_cb,
               maxsize='10M')
f

The list of files was sent to the callback, but you can also get the list with the list() method


In [ ]:
f.list()

In [ ]:
# check it
!ls -l tmpdir

In [ ]:
!rm -rf tmpdir

Multiple File Uploads


In [ ]:
# This will allow you to select a multiple files to be uploaded.
fm = FileUpload("Really Interesting Files", 
               "This is a description that appears when the mouse hovers over the name.", 
                cb=done_cb, maxnum=3, maxsize='10M')
fm

In [ ]:
# The default directory is 'tmpdir'.  Lets check it
!ls -l tmpdir

In [ ]:
fm.list()

Basic Widget without Label

Just display the ".input" part of the widget.


In [ ]:
fb = FileUpload("Some Files", 
                "",
                maxsize='1G',
                cb=done_cb,
                maxnum=10,
                basic=True)
fb

ipywidgets compatibility


In [ ]:
from ipywidgets import VBox, Button

b = Button(description='Button1')
fx = FileUpload("Some Files", 
                "",
                maxsize='1G',
                cb=done_cb,
                maxnum=10,
                basic=True)
VBox([b, fx.w])