我不明白
file_uploader
组件以及 UploadedFile
类如何工作。
我希望用户通过组件上传文件,然后将其放入 Snowflake 阶段。我很想使用临时文件库,但我担心这可能没有必要,因为
UploadedFile
已经达到了目标,
这是我想要完成的伪代码
import yaml
import streamlit as st
# This works fine
uploaded_file = st.file_uploader(
label="Upload your semantic model (YAML) file.",
accept_multiple_files=False,
type=["yaml"],
)
# This works
if uploaded_file:
# How do I upload the file with a specific file name?
st.session_state.session.file.put(
local_file_name="", # Unsure what I need to do here...
stage_location="@STAGE",
auto_compress=False,
overwrite=True
)
我想做的是..
from io import StringIO
import yaml
import tempfile
import streamlit as st
uploaded_file = st.file_uploader(
label="Upload your semantic model (YAML) file.",
accept_multiple_files=False,
type=["yaml"],
)
if uploaded_file:
stringio = StringIO(uploaded_file.getvalue().decode("utf-8"))
string_data = stringio.read()
yaml_data = yaml.safe_load(string_data)
with tempfile.NamedTemporaryFile(delete=False, mode='w', prefix='TEST_', suffix='_.yaml') as temp_file:
print(temp_file.name)
yaml.dump(data, temp_file)
st.session_state.session.file.put(
local_file_name=temp_file.name,
stage_location="@STAGE",
auto_compress=False,
overwrite=True
)
file_uploader()
文档
Snowflake 中的 Streamlit 不支持上传文件。
Snowflake 中的 Streamlit 不支持以下 Streamlit 功能:
st.bokeh_chart
st.camera_input
st.反馈
st.file_uploader
(还有其他功能不支持。您可以在下面的链接中查看它们)