I plan to use tempfile to read a pdf file and store it. Then open the file in a DIFFERENT function and upload it to a flask table as a BLOB.
I currently have the following code which I THINK would upload multiple files to the tempfile 'storage', ( This is untested so I do not know if the files would just overwrite each over, and thus when I go to read them there would only be 1 )
I do not know if the tempfile method is the correct way of solving this issue, I assume i am missing an import in the 2nd function, or a specific way of opening the tempfiles. Anyone who has an idea on how to solve this error or can point me to helpful documentation with examples I would be very grateful.
Jack
I currently have the following code which I THINK would upload multiple files to the tempfile 'storage', ( This is untested so I do not know if the files would just overwrite each over, and thus when I go to read them there would only be 1 )
def 1 ... for file in uploaded_files: if allowed_file(file.filename): temp_filename = secure_filename(file.filename) filenames.append(temp_filename) my_temp_file=tempfile.NamedTemporaryFile(delete=False) file.save(my_temp_file) file.temp_name=my_temp_file.name ...I then want to access the tempfile 'storage' in a 2nd function. Something along the lines of:
def 2 ... for name in filenames: actual_file=open(temp.name, 'rb')I had been previously using globals to do this but figured out that my database will be used by multiple people, which of cause means globals are a huge no no.
for file in pdf_values: actual_file=open(file.temp_name, 'rb')Where pdf_values is a global set by : set_pdf_values(uploaded_files) .
I do not know if the tempfile method is the correct way of solving this issue, I assume i am missing an import in the 2nd function, or a specific way of opening the tempfiles. Anyone who has an idea on how to solve this error or can point me to helpful documentation with examples I would be very grateful.
Jack