-
-
Save carlosa8c/28a95ccba6db95091352b484ca6dacf9 to your computer and use it in GitHub Desktop.
pyazo server side
This file contains hidden or 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
from flask import Flask, request, redirect, url_for | |
import os | |
import random | |
import string | |
UPLOAD_FOLDER = '/var/www/html/uploads' | |
app = Flask(__name__) | |
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER | |
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif']) | |
def id_generator(size=6, chars=string.ascii_letters + string.digits): | |
return ''.join(random.choice(chars) for _ in range(size)) | |
def allowed_file(filename): | |
return '.' in filename and \ | |
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS | |
@app.route('/', methods=['POST']) | |
def upload(): | |
if request.method == 'POST': | |
if 'file' not in request.files: | |
return 'No file' | |
file = request.files['file'] | |
if file and allowed_file(file.filename): | |
filename = id_generator()+'.png' | |
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) | |
return filename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment