Create a new virtual environment somewhere you'd like to place these files.
python3.9 -m venv uploadtest
cd uploadtest
. bin/activate
Then drop these files in that directory. Install dependencies:
pip3 install -r requirements.txt
Spin up the debugger:
wdb.server.py &
This will potentially produce a fair amount of output, especially once active. We've spawned it in the background, when done, run fg
and ⌃C it to stop. Also use ⌃C to stop the development-time web server which we now spin up:
python app.py
Open http://localhost:8080 in a browser, be presented with a file upload form.
I select a folder named sample
containing two top-level screenshot PNGs and a subfolder named deeper
containing a third screenshot with the date 04-14
.
Submitting, I'm dropped into the WDB interactive debugger. We can now explore the uploaded data passed to our endpoint as data
.
>>> data
{'files': [
FieldStorage('files', 'Screen Shot 2022-04-19 at 19.17.52.png'),
FieldStorage('files', 'Screen Shot 2022-04-14 at 09.28.50.png'),
FieldStorage('files', 'Screen Shot 2022-04-20 at 10.30.09.png')
]}
The interesting one is the deeper screenshot, the second element uploaded in this case. (Order is not gauranteed.)
>>> data['files'][1].name, data['files'][1].filename
('files', 'Screen Shot 2022-04-14 at 09.28.50.png')
The field name is correct, and the name contains no path information. Now we can drop the doozie:
>>> data['files'][1].__dict__
...
There will be a lot of data. These are all of the instance–local attributes. We can look in here for the word deeper
… which is not found.
The requirements are split between "universal / packaging", "web framework", and "debugger". Clearly, a debugger is a bit more complex than the application we're writing here.