Black Lives Matter. Please consider donating to Black Girls Code today.

Uploading mdf files

I’m making an app with plotly-dash to view *.mdf files (Python Library asammdf for loading the files). I made an Upload component (https://dash.plot.ly/dash-core-components/upload) to load the files. I thought of taking the full filename to pass this to the MDF function in the asammdf library to load the file and put data in a graph. However the dash Upload component only returns the filename and not the complete path so I cannot use the MDF function on this. The Upload component also outputs the content of the file as a binary string but not sure how I can pass this to the MDF function.

Somebody knows a way forward for this problem?

I recommend using a dcc.Dropdown control with options that are filenames from your filesystem. See a response here: Get file path from upload component.

We should make this more clear in our documentation, I’ve created an issue about that here: https://github.com/plotly/dash-docs/issues/335

I want the user to be able to read in any file on their local driver or network drive so I don’t think a dropdown control can work here?

Actually I found out it is possible to work with the contents variable. The MDF function (as well as most read in functions I assume) check if the input is a ‘file like’ object or a string. If it is a ‘file like’ object, it directly reads from this object. The contents can be transformed as follows:

content_type, content_string = contents[0].split(’,’)
decoded = base64.b64decode(content_string)
file_like_object = io.BytesIO(decoded)

This works out fine for my application.