Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Commit

Permalink
Add basic upload form on GET /upload
Browse files Browse the repository at this point in the history
  • Loading branch information
BBaoVanC committed Jan 24, 2021
1 parent c1d5f90 commit 8368f9b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
9 changes: 4 additions & 5 deletions imgupload.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ def discord(image):
return jsonify({'status': 'error', 'error': 'NOT_FOUND'}), status.HTTP_404_NOT_FOUND


@app.route("/upload", methods = ["POST"])
@app.route("/upload", methods = ["GET", "POST"])
def upload():
if request.method == "POST": # sanity check: make sure it's a POST request
if request.method == "GET":
return render_template("upload.html", settings = settings)
else:
print("Request method was POST!")

with open("uploadkeys", "r") as keyfile:
Expand Down Expand Up @@ -197,9 +199,6 @@ def upload():
else: # if uploadKey was not found in request body
print("No uploadKey found in request!")
return jsonify({'status': 'error', 'error': 'UNAUTHORIZED'}), status.HTTP_401_UNAUTHORIZED
else: # if the request method wasn't post (this cannot happen)
print("Somehow the request method was not POST!")
return jsonify({'status': 'error', 'error': 'WRONG_METHOD'}), status.HTTP_405_METHOD_NOT_ALLOWED

if __name__ == "__main__":
print("Run with `flask` or a WSGI server!")
16 changes: 16 additions & 0 deletions templates/upload.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<html>
<body>
<form action="{{ settings.ROOTURL }}upload" method="POST" enctype="multipart/form-data">
<p>
<input type="file" name="imageUpload" id="imageUpload" />
</p>
<p>
<input type = "text" id = "uploadKey" name = "uploadKey" />
<label for = "uploadKey">uploadKey</label>
</p>
<p>
<input type="submit" value="submit" />
</p>
</form>
</body>
</html>

0 comments on commit 8368f9b

Please sign in to comment.