checking file duplicates seems to work, didnt check in could tho

master
Kostanjevec 2022-06-15 02:55:22 +02:00
parent 58eb61c201
commit 7ac982e2b5
1 changed files with 9 additions and 12 deletions

View File

@ -34,26 +34,23 @@ def upload_file():
username = session["username"]
if request.method == 'POST':
#flask gets the file
#print(list(request.files)[0][1])
#upload = request.files["file"]
#print(upload)
#uploads = list(request.files)[0]
#print(uploads)
print(request.files)
#@TODO ta forloop bi lahko flashal postopoma
for upload in request.files.getlist("file"):
filename = secure_filename(upload.filename)
# Is there really a file?
if not filename:
flash('There is no file. Try again?')
return render_template("menu/upload.html", username=username)
script_path = os.path.dirname(os.path.abspath(__file__))
temp_path = os.path.join(script_path, "temp")
#prevent duplicate filenames
print(filename)
if dbsession.query(Card).filter(Card.title == filename).first() != None:
flash("Filename already in database, please rename if you want to upload: " + filename, 'error')
continue
script_path = os.path.dirname(os.path.abspath(__file__)) #where are we
temp_path = os.path.join(script_path, "temp") #where is the temp file
# @TODO ne dela za več fajlov
# a lot of stuff can wrong here and nobody may know
with tempfile.NamedTemporaryFile(dir=temp_path, delete=False) as fp:
fp.write(upload.stream.read())