Save uploaded files in sql server

hi
i want to save uploaded file( image) in my sql server but show this error :
ProgrammingError: ('Invalid parameter type. param-index=9 param-type=UploadedFile', 'HY105')

Traceback:

 add_data(BBN,RT,HD,LF,LM,WM,WL,RLW,FE,image)
c2.execute('INSERT INTO bdata(BBN,RT,HD,LF,LM,WM,WL,RLW,FE,image) VALUES (?,?,?,?,?,?,?,?,?,?)',(BBN,RT,HD,LF,LM,WM,WL,RLW,FE,image)

this is part of my code :

STONE=['Magnetite', 'Hematite', 'Soil', 'Waste Rock', 'Cong-Waste Rock',
'Conglomerate', 'magn-Waste Rock', 'Soil-Cong', 'Soil-Waste Rock', 'So-Co-Waste Rock']
RT=st.selectbox('Rock Type:',STONE)
HD=st.radio('Hole Diameter:',( 8.5, 10.5, 6.5, 7.5))
image = st.file_uploader("Upload", type="jpg")
if st.button("Add row"):
add_data(BBN,RT,HD,LF,LM,WM,WL,RLW,FE,image)
st.success("You have successfully added Blast")
sql_query = pd.read_sql_query('SELECT * FROM Blast.dbo.bdata',conn2)
st.write("DATABASE")
st.write(sql_query)
 st.write("\n")

Hi @Mohammadseif -

This type of error is usually unrelated to Streamlit, meaning, if the SQLServer library you are using doesn’t like how you are passing it data, then you need to troubleshoot it there.

I would suggest making sure you can upload your data to SQLServer without using Streamlit, then making your Streamlit code work with that process. Meaning, Streamlit will return a BytesIO buffer from file_uploader. So you either need to confirm that your SQL Server library will take a BytesIO buffer, or convert it to the data type it is looking for.

Best,
Randy

thanks my dear friend randy…i solved it …i have saved uploaded file in my pc and save file path in sql server database … i added a columns in my database with NVARCHAR type and done issue :pray: :pray: :pray: :pray:
my new problem is:

How to clear the cache with each run and reseting my widget??

i put my app in my github account where you can see… I want to cache widget for “input data section” in app after each add data …

(line 93-136)

1 Like