Uploading MS Access File to Dash

Like the subject says, I am building a web app that decomposes an MS Access database file into its component tables (export as CSV).

The whole point is to use dcc.Upload to pass the .mdb file into the server so my ts_db.py script can parse the file and return the CSV files as exports.

However, when I use the following code, the script does not process the .mdb file like it does on my local Python interpreter:

# ======================== App Layout
upload = html.Div(
    dcc.Upload(
        id="upload-data",
        children=html.Div(
            ["Drag and Drop or ", html.A("Select TestStand .mdb File to Process")]
        ),
        style={
            "width": "95%",
            "height": "60px",
            "lineHeight": "60px",
            "borderWidth": "3px",
            "borderStyle": "dashed",
            "borderRadius": "10px",
            "textAlign": "center",
            "margin": "20px",
        },
    ),
)
output_data = html.Div(id="output-data-upload")

app.layout = html.Div([upload, output_data])

# ======================== App Callbacks/FileIO
@app.callback(
    Output("output-data-upload", "children"),
    Input("upload-data", "contents"),
    Input("upload-data", "filename"),
)
def import_contents(contents, filename):
    """Open TestStand database (.mdb) with user prompt"""
    if contents:
        content_type, content_string = contents.split(",")
        decoded = base64.b64decode(content_string)
        file_like_object = io.BytesIO(decoded)
        db_filename = file_like_object
        print(db_filename)

        """Execute core python script to decompose the TestStand database file"""
        ts_db.main(db_filename)

        children = [filename]
        return children

Any advice or insight would be appreciated!

May peace be with you,
Ahmed

Hi @Ash010110 ,

What is filename in your case? On first sight, it seems to be a string. How do you store the uploaded content?

Hi AIMPED,

So my core problem is “how to store the uploaded content.”

In my original python script, I would pass the TestResults.mdb file along with its filepath and the script would do all the processing. But now I am trying to allow users to push their TestResults.mdb file to the server so my script can decompose them for general use as CSV files.

Not sure if Dash actually allows files to be stored in the server. The point of the Dash app was to ‘upload’ the .mdb file so I can run all my SQL queries and python manipulations to decompose the Access database to its component tables in CSV format.

May peace be with you,
Ahmed