checking file duplicates seems to work, didnt check in could tho
parent
58eb61c201
commit
7ac982e2b5
21
upload.py
21
upload.py
|
@ -34,26 +34,23 @@ def upload_file():
|
||||||
username = session["username"]
|
username = session["username"]
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
#flask gets the file
|
#@TODO ta forloop bi lahko flashal postopoma
|
||||||
#print(list(request.files)[0][1])
|
|
||||||
#upload = request.files["file"]
|
|
||||||
#print(upload)
|
|
||||||
|
|
||||||
#uploads = list(request.files)[0]
|
|
||||||
#print(uploads)
|
|
||||||
print(request.files)
|
|
||||||
for upload in request.files.getlist("file"):
|
for upload in request.files.getlist("file"):
|
||||||
filename = secure_filename(upload.filename)
|
filename = secure_filename(upload.filename)
|
||||||
# Is there really a file?
|
# Is there really a file?
|
||||||
if not filename:
|
if not filename:
|
||||||
flash('There is no file. Try again?')
|
flash('There is no file. Try again?')
|
||||||
|
|
||||||
return render_template("menu/upload.html", username=username)
|
return render_template("menu/upload.html", username=username)
|
||||||
|
|
||||||
script_path = os.path.dirname(os.path.abspath(__file__))
|
#prevent duplicate filenames
|
||||||
temp_path = os.path.join(script_path, "temp")
|
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
|
# a lot of stuff can wrong here and nobody may know
|
||||||
with tempfile.NamedTemporaryFile(dir=temp_path, delete=False) as fp:
|
with tempfile.NamedTemporaryFile(dir=temp_path, delete=False) as fp:
|
||||||
fp.write(upload.stream.read())
|
fp.write(upload.stream.read())
|
||||||
|
|
Loading…
Reference in New Issue