Flask-Cloudy 0.10.0

This commit is contained in:
Mardix
2015-07-30 00:46:30 -04:00
parent 618ce43487
commit a9a15d3fc6
10 changed files with 183 additions and 39 deletions
+1
View File
@@ -0,0 +1 @@
__author__ = 'mardochee.macxis'
+37
View File
@@ -0,0 +1,37 @@
from flask import Flask, request, render_template, redirect, abort, url_for
from flask_cloudy import Storage
app = Flask(__name__)
app.config.update({
"STORAGE_PROVIDER": "LOCAL",
"STORAGE_CONTAINER": "./data",
"STORAGE_KEY": "",
"STORAGE_SECRET": "",
"STORAGE_SERVER": True
})
storage = Storage()
storage.init_app(app)
@app.route("/")
def index():
return render_template("index.html", storage=storage)
@app.route("/view/<path:object_name>")
def view(object_name):
obj = storage.get(object_name)
print obj.name
return render_template("view.html", obj=obj)
@app.route("/upload", methods=["POST"])
def upload():
file = request.files.get("file")
my_object = storage.upload(file)
return redirect(url_for("view", object_name=my_object.name))
if __name__ == "__main__":
app.run(debug=True, port=5000)
+3
View File
@@ -0,0 +1,3 @@
Hello World!
from flask_cloud import Storage
+39
View File
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Flask-Cloudy</title>
</head>
<body>
<h1>Flask-Cloudy</h1>
<form action="{{ url_for('upload') }}" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="file" id="fileToUpload"> <br>
<input type="submit" value="Upload File" name="submit">
</form>
<hr>
<h3>List of files available on the storage:</h3>
<table>
<thead>
<th>Name</th>
<th>Size</th>
</thead>
<tbody>
{% for obj in storage %}
<tr>
<td><a href="{{ url_for('view', object_name=obj.name) }}">{{ obj.name }}</a></td>
<td>{{ obj.size }} bytes</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>
+23
View File
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Flask-Cloudy</title>
</head>
<body>
<h1>Flask-Cloudy: View File</h1>
<a href="{{ url_for('index') }}"><- Home</a>
<br> <br>
Name: {{ obj.name }} <br><br>
Size: {{ obj.size }} bytes <br><br>
Short url: {{ obj.short_url }} <br><br>
View file: <a href="{{ obj.url }}">{{ obj.url }}</a> <br><br>
{% set download_url = obj.download_url() %}
Download: <a href="{{ download_url }}">{{ download_url }}</a> <br><br>
</body>
</html>