Hi,
How would I go about uploading multiple files from a local file location on my PC, without using the file_uploader() because I don’t need a user to select anything?
Hi,
How would I go about uploading multiple files from a local file location on my PC, without using the file_uploader() because I don’t need a user to select anything?
Hi Chai86
This is an example to get a list of all files in the specified directory
import streamlit as st
import os
def list_files(directory):
return [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]
def main():
st.title("Upload Multiple Files")
local_folder_path = "D:\\Users\\ES000881\\Desktop\\Libros"
files = list_files(local_folder_path)
st.sidebar.header("Files in the Local Folder")
selected_files = st.sidebar.multiselect("Select files to upload", files)
st.write("Selected Files:")
for file in selected_files:
st.write(f"- {file}")
if __name__ == "__main__":
main()
Hi Oscar,
Does that achieve basically what this does?:
pdffile = st.file_uploader("Upload your PDFs here:", type="pdf", accept_multiple_files=True)
As in the pdffile
is your equivalent of files
, or are they different in any way?
So, in essence, the pdffile and my code are serving similar purposes—they both represent a list of files that users can interact with. However, pdffile is specifically designed for file uploading, while files in my provided code represents pre-existing files in a local folder that users can select from.
Hi Oscar,
What i meant to say (i should be clearer sorry) is that: are the pdffile
and your files
here, the same object. i… do they contain the same information such that if i want to go on and do some process on these documents?
Certainly! Yes, indeed. While st.file_uploader()
is used to directly upload PDF files, the provided code searches for PDF files in a specific local folder. You can create an additional widget, such as st.selectbox()
, to allow users to select the PDF they want to view from the list of files available in the local folder. This way, you can achieve similar functionality and give users the option to choose from the available PDF files in the folder.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.