Drag and Drop - How to use the file

Summary

How is it possible to use the result of drag and drop (use the second part to display the pdf that was dragged and dropped.

Steps to reproduce

Code snippet:

    uploaded_files = st.file_uploader("Choose a CSV file", accept_multiple_files=True)
    for uploaded_file in uploaded_files:
        bytes_data = uploaded_file.read()
        st.write("filename:", uploaded_file.name)
        st.write(bytes_data)
        base64_pdf = base64.b64encode(bytes_data.read()).decode('utf-8')
        pdf_display = F'<iframe src="data:application/pdf;base64,{base64_pdf}" width="700" height="1000" type="application/pdf"></iframe>'   
        st.markdown(pdf_display, unsafe_allow_html=True)

    #Faire une fonction avec le display
    with open(bytes_data,"rb") as f:
      base64_pdf = base64.b64encode(f.read()).decode('utf-8')
    
    pdf_display = F'<iframe src="data:application/pdf;base64,{base64_pdf}" width="700" height="1000" type="application/pdf"></iframe>'   
    st.markdown(pdf_display, unsafe_allow_html=True)

    st.write('Statistics')
    st.image('Statistics on Icebreakers.png')

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:

It should display pdf

Actual behavior:

It does not work properly - does not display

You should be getting NameError in line 10 in the first run, since bytes_data is undefined at that point. But you don’t mention any errors so I don’t know what could be going on.

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