The request.files dictionary holds files being sent from the browser to Flask.
The send_from_diretory function sends a file to the browser.
So, they are used in opposite situations.
Uploading is the first situation, while getting the file back out is the second.
I think it's in memory until you .save() the file to a pathname of your choosing. It might be temporarily on disk someplace, but it really doesn't matter.
If you want to keep it, you have to .save() it somewhere.
Great question! If the file is for everyone, uploading it to /static is perfectly reasonable.
But let's think of a different situation. The app is some social media kinda thing, and Hermione has shared a picture with Ron (maybe it's a little naughty), but she does *not* want to share it with Malfoy, who she knows also uses the site.
If Malfoy is logged in, he will have access to everything in the /static folder. He might need to guess some filenames, but sometimes that's possible.
Alternatively, we force users to go through
a /pic/<nnn> endpoint that checks the
sharing permissions for the picture. Now, Malfoy can't see the picture.
By forcing people to go through an endpoint, we can impose whatever rules we want, while /static is for things that are public, such as logo images.
Good question. You can store the files in the directory with the appropriate type extension, and then store the entire filename, including the extension, in a database table associated with the entity.
Some files are defined that way, particularly PHP and CGI. Many web servers will automatically execute such files; that's what the files are for.
Assuming it has a specific fileame, like nm123.jpg
(profile picture for George Clooney), your upload code can (1) check
for an existing picture and (2) delete
it. The os.unlink() function will do that.
The popup is determined by the browser, possibly influenced by some modal with bootstrap or tailwind CSS, hence the boring sameness.
Yay!