Created
November 11, 2012 15:44
-
-
Save n9986/4055267 to your computer and use it in GitHub Desktop.
Flask route for use with https://github.com/valums/file-uploader
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
@app.route('/upload/foo', methods=['POST']) | |
@roles_required('admin') | |
def upload_image(): | |
image_name = request.args['qqfile'] | |
product_image_path = os.path.join(app_config('IMG_PATH'), image_name) | |
product_thumbnail_path = os.path.join(app_config('THUMB_PATH'), image_name) | |
with open(product_image_path, 'w') as fh: | |
fh.write(flask.request.stream.read()) | |
im = Image.open(product_image_path) | |
with open(product_thumbnail_path, 'w') as fh: | |
image_resize(im, (260, 180), False, fh) | |
return json.dumps({"success": True, "image_name": image_name, "thumb_path": url_for('static', filename="thumbs/" + image_name)}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment