How to upload multiple PDF files WITHOUT using file_uploader()?


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__":

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.