@app.route("/upload", methods=["GET", "POST"])
def upload():
if request.method == "GET":
return render_template("upload.html")
obj = request.files.get("file")
print(obj)
print(obj.filename)
print(obj.stream)
ret_list = obj.filename.rsplit(".", maxsplit=1)
if len(ret_list) != 2:
return "Please upload zip file"
if ret_list[1] != "zip":
return "Please upload zip file"
obj.save(os.path.join(BASE_DIR, "files", obj.filename))
target_path = os.path.join(BASE_DIR, "files", str(uuid.uuid4()))
shutil._unpack_zipfile(obj.stream, target_path)
file_path = os.path.join(BASE_DIR, "files", obj.filename)
obj.save(file_path)
target_path = os.path.join(BASE_DIR, "files", str(uuid.uuid4()))
ret = unzip_file(file_path, target_path)
os.remove(file_path)
if ret:
return ret
return "Upload successful"