Steamlit - Upload and use User Shapefile and Tif File

Hello @Geobro1!

If you have a package like pyosp that requires an actual file path, one option is to use NamedTemporyFile, like this (this example uses PIL, but it should work with any library that is reading from a file)

from tempfile import NamedTemporaryFile

import streamlit as st
from PIL import Image

uploaded = st.file_uploader("Upload a file", type=["tif"])

if uploaded:
    with NamedTemporaryFile("wb", suffix=".tif") as f:
        f.write(uploaded.getvalue())
        # f.name is the path of the temporary file
        im = Image.open(f.name)
1 Like