-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flask framework with uploading photos
- Loading branch information
0 parents
commit a243c0c
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from flask import Flask, render_template, request, redirect, url_for, send_from_directory | ||
from werkzeug import secure_filename | ||
import requests | ||
import os | ||
|
||
app = Flask(__name__) | ||
app.config['DEBUG'] = True | ||
app.config['UPLOAD_FOLDER'] = 'uploads' | ||
app.config['FILE_EXTENSIONS'] = ['png', 'jpg', 'pdf', 'jpeg', 'gif'] | ||
|
||
def allowed_file(filename): | ||
return '.' in filename and filename.rsplit('.', 1)[1] in app.config['FILE_EXTENSIONS'] | ||
|
||
@app.route('/') | ||
def index(): | ||
return render_template('index.html') | ||
|
||
@app.route('/upload', methods=['GET', 'POST']) | ||
def uploadFile(): | ||
if request.method == 'POST': | ||
fileObj = request.files['file'] | ||
if fileObj and allowed_file(fileObj.filename): | ||
safeFile = secure_filename(fileObj.filename) | ||
fileObj.save(os.path.join(app.config['UPLOAD_FOLDER'], safeFile)) | ||
return redirect(url_for('uploaded_file', filename=safeFile)) | ||
|
||
@app.route('/uploads/<filename>') | ||
def uploaded_file(filename): | ||
return send_from_directory(app.config['UPLOAD_FOLDER'], filename) | ||
|
||
if __name__ == '__main__': | ||
app.run(host='0.0.0.0') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Flask | ||
Flask-Login==0.4.0 | ||
Flask-WTF==0.13.0 | ||
Jinja2==2.8 | ||
MarkupSafe==0.23 | ||
WTForms==2.1 | ||
Werkzeug==0.10.4 | ||
argparse==1.2.1 | ||
flask-mongoengine==0.8.2 | ||
itsdangerous==0.24 | ||
mongoengine==0.11.0 | ||
pymongo==3.4.0 | ||
request==2.2.1 | ||
six==1.10.0 | ||
wsgiref==0.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" | ||
rel="stylesheet"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<div class="header"> | ||
<h3 class="text-muted">How To Upload a File</h3> | ||
</div> | ||
<hr/> | ||
<div> | ||
|
||
<form action="upload" method="post" enctype="multipart/form-data"> | ||
<input type="file" name="file"><br /><br /> | ||
<input type="submit" value="Upload"> | ||
</form> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |