St.file_uploader with TDMtermite (requires path of file)

Hi,

I try to read and process TDM and TDX files with python and streamlit.
The TDM file is a xml formated header file and the TDX file contains the measurement data as binary. Writing TDM and TDMS Files in LabVIEW - NI

For reading the files I use the package TDMterrmite. TDMtermite · PyPI

I upload the TDM and TDX files with st.fileuploader and try to pass them as input to the TDMtermite package but it seems that the TDMtermite package needs the path to a file and not a uploaded file.

This is the example code for TDMtermite:

import TDMtermite
import re

try :
jack = TDMtermite.tdmtermite(b’samples/SineData.tdm’,b’samples/SineData.tdx’)
except RuntimeError as e :
print("failed to load/decode TDM files: " + str(e))

I tried the following with streamlit:

files_tdm = st.file_uploader("TDM ", type=[“TDM”,“TDX”], accept_multiple_files=False)
files_tdx = st.file_uploader("TDX ", type=[“TDM”,“TDX”], accept_multiple_files=False)

try :
data_raw = TDMtermite.tdmtermite(files_tdm,files_tdx)
except RuntimeError as e :
print("failed to load/decode TDM files: " + str(e))

I get the error from TDMtermite: TypeError: expected bytes, NoneType found

Is it smehow possible to pass the “path to the cash” where the data is to a package?

Save the bytes to a NamedTemporaryFile as advised in this post:

Hi Goyo,
thanks for the quick reply, this solved my problem.