@jinnyzor thank you for you quick reply. Sorry it took long to respond. I am having no luck figuring this out. If the file is within max_size it loads, crickets if not. I tried using style_reject. I expect the dcc.Upload style to change if the files is bigger than max_size, but it does not.
from dash import Dash, dcc, html, dash_table, Input, Output, State, callback
import base64
import datetime
app = Dash(__name__)
app.layout = html.Div(
[
dcc.Upload(
id="upload-data",
children=html.Div(["Drag and Drop or ", html.A("Select Files")]),
max_size=4,
style={
"width": "100%",
"height": "60px",
"lineHeight": "60px",
"borderWidth": "1px",
"borderStyle": "dashed",
"borderRadius": "5px",
"textAlign": "center",
},
style_reject={
"borderStyle": "solid",
"borderColor": "#8B4513",
"backgroundColor": "#FF0000",
},
style_active={
"borderWidth": "1px",
},
# Allow multiple files to be uploaded
multiple=False,
),
html.Div(id="output-data-upload"),
]
)
def parse_contents(contents, filename, date):
data_received = base64.decodebytes(
contents.encode("utf8").split(b";base64,")[1]
)
return html.Div(
[
html.H5(filename),
html.H6(datetime.datetime.fromtimestamp(date)),
html.P(f"Data: {data_received}"),
html.Hr(), # horizontal line
# For debugging, display the raw contents provided by the web browser
html.Div("Raw Content"),
]
)
@callback(
Output("output-data-upload", "children"),
Input("upload-data", "contents"),
State("upload-data", "filename"),
State("upload-data", "last_modified"),
)
def update_output(contents, filename, modified):
if contents is not None:
return parse_contents(contents, filename, modified)
else:
return None
if __name__ == "__main__":
app.run(debug=True, port=8090, host="0.0.0.0")