St.file_uploader with TDMtermite

Hello,
i know there was a topic with similar problems but still i couldnt fix it yet. I want to work with st.file_uploader and upload TDM and TDX files. Then i want to read these files using TDMtermite. My approach is similar to: st.file_uploader TDMtermite

My Problem is that I always get this error: failed to load tdm file: failed to parse XML tree: Error reading from file/stream because my .TDX file is empty. So my question is why is the TDX file empty but the TDM file is not? What should i change?
I am very thankful for every help!

from tempfile import NamedTemporaryFile
import TDMtermite
import streamlit as st
#upload my TDX and TDM files
uploaded_tdx = st.file_uploader("TDX Dateien hochladen", accept_multiple_files=True, type=["TDX"])
uploaded_tdm = st.file_uploader("TDM Dateien hochladen", accept_multiple_files=True, type=["TDM"])

myfiles =[]
#extract the file names
if uploaded_tdm is not None:
    for i in range(len(uploaded_tdm)):
        myfiles.append(uploaded_tdm[i].name)



for i in range(len(uploaded_tdm)):
  #Save data to a temp File
  with NamedTemporaryFile("wb", suffix=".TDM", prefix=Path(myfiles[i]).stem) as f_TDM,\
       NamedTemporaryFile("wb", suffix=".TDX", prefix=Path(myfiles[i]).stem) as f_TDX :
      f_TDM.write(uploaded_tdm[i].getvalue())
      f_TDX.write(uploaded_tdx[i].getvalue())

      TDM_name = f_TDM.name
      TDX_name = f_TDX.name
            
            
      current_file = TDMtermite.tdmtermite(TDM_name.encode('ascii'), TDX_name.encode('ascii'))



This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.