Skip to content

Instantly share code, notes, and snippets.

@n9986
Created November 11, 2012 15:44
Show Gist options
  • Save n9986/4055267 to your computer and use it in GitHub Desktop.
Save n9986/4055267 to your computer and use it in GitHub Desktop.
Flask route for use with https://github.com/valums/file-uploader
@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