I have made a flask server REST API that does an upload to a specific folder. The upload must comply to a specific file extension, and must be in a specific folder.
So i made these two app.configs:
JavaScript
x
3
1
app.config['UPLOAD_EXTENSIONS'] = ['.stp', '.step']
2
app.config['UPLOAD_PATH'] = 'uploads'
3
However, i want to make a new route, for a new upload of a specific file extension to another folder.
So can i have two sets of app.config['UPLOAD_EXTENSIONS']
and app.config['UPLOAD_PATH']
?
One set will be for extension1
in folder1
and the other set for extension2
in folder2
.
Advertisement
Answer
Try using the extension Flask-Uploads .
Or, proceeding from the file format, form a subdirectory in your UPLOAD_PATH.
JavaScript
1
16
16
1
import os
2
3
4
def select_directory(filename: str) -> str:
5
file_format = filename.split('.')[1]
6
your_path1 = 'path1'
7
your_path2 = 'path2'
8
9
if file_format in ('your format1', 'your format2'):
10
full_path = os.path.join(app.config['UPLOAD_FOLDER'], your_path1, filename)
11
else:
12
full_path = os.path.join(app.config['UPLOAD_FOLDER'], your_path2, filename)
13
14
return full_path
15
16