Commit d5403dc
feat: add file upload support and utility functions to client library
This update adds file uploading support to the Dioptra client library through a new DioptraFile
class, supporting utility functions, and extending the client's post method to accept `data` and
`files` arguments. The changes enable users to upload single files, multiple files, or all files
within a directory while enforcing strict path validation in the associated filenames to prevent
server-side directory traversal attacks.
The new functionality includes:
- A DioptraFile class that validates filenames to ensure they are normalized, POSIX-compliant
relative paths without traversal components (e.g., "..").
- File selection utility functions:
- select_files_in_directory: Recursively selects files from a directory with optional regex
pattern filtering
- select_one_or_more_files: Selects individual files with optional renaming support to handle
filename collisions
- Extended POST request in the client to handle multipart form data that contains regular form
fields and file uploads. All file uploads, whether they're single file or multiple files, are
streamed to the server.
The DioptraSession implementation for the requests-based client and the Flask test client have both
been updated to support the new functionality.1 parent 3e6eaaf commit d5403dc
6 files changed
Lines changed: 682 additions & 6 deletions
File tree
- src/dioptra/client
- tests/unit
- client
- restapi/lib
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| 28 | + | |
| 29 | + | |
26 | 30 | | |
| 31 | + | |
27 | 32 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
19 | 23 | | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
23 | 27 | | |
| 28 | + | |
| 29 | + | |
24 | 30 | | |
25 | 31 | | |
26 | 32 | | |
| |||
91 | 97 | | |
92 | 98 | | |
93 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
94 | 146 | | |
95 | 147 | | |
96 | 148 | | |
| |||
117 | 169 | | |
118 | 170 | | |
119 | 171 | | |
| 172 | + | |
| 173 | + | |
120 | 174 | | |
121 | 175 | | |
122 | 176 | | |
| |||
129 | 183 | | |
130 | 184 | | |
131 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
132 | 190 | | |
133 | 191 | | |
134 | 192 | | |
| |||
179 | 237 | | |
180 | 238 | | |
181 | 239 | | |
| 240 | + | |
| 241 | + | |
182 | 242 | | |
183 | 243 | | |
184 | 244 | | |
| |||
188 | 248 | | |
189 | 249 | | |
190 | 250 | | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
191 | 255 | | |
192 | 256 | | |
193 | 257 | | |
| |||
311 | 375 | | |
312 | 376 | | |
313 | 377 | | |
| 378 | + | |
| 379 | + | |
314 | 380 | | |
315 | 381 | | |
316 | 382 | | |
| |||
323 | 389 | | |
324 | 390 | | |
325 | 391 | | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
326 | 396 | | |
327 | 397 | | |
328 | 398 | | |
329 | 399 | | |
330 | 400 | | |
331 | | - | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
332 | 407 | | |
333 | 408 | | |
334 | 409 | | |
| |||
0 commit comments