Skip to content

Instantly share code, notes, and snippets.

@nickknissen
Forked from lost-theory/cloudinary.py
Created August 22, 2013 08:34
Show Gist options
  • Save nickknissen/6304615 to your computer and use it in GitHub Desktop.
Save nickknissen/6304615 to your computer and use it in GitHub Desktop.
from flask import request, Flask
from cloudinary import uploader #pip install git+https://github.com/cloudinary/pycloudinary/
class Cloudinary(object):
def __init__(self, app):
config = app.config['CLOUDINARY_URL'].split('://')[1]
config = config.replace("@", ":")
self.api_key, self.api_secret, self.name = config.split(":")
def upload_image(self, image):
keys = {'public_id': 1001}
res = uploader.call_api(
"upload",
uploader.build_upload_params(**keys),
api_key=self.api_key,
api_secret=self.api_secret,
cloud_name=self.name,
file=image.stream,
)
return res
###############################################################################
app = Flask(__name__)
app.config['DEBUG'] = True
app.config['CLOUDINARY_URL'] = "cloudinary://347452728366389:30n0mSGxiSYZw7q3dZ_3hjorJ5M@ummwut" #XXX: feel free to use this URL, upload whatever you like ;)
cloudinary = Cloudinary(app)
###############################################################################
@app.route("/", methods=['GET', 'POST'])
def test():
if request.method == "POST":
json_result = cloudinary.upload_image(request.files['image'])
return str(json_result)
return '<html><body><form action="" method=post enctype=multipart/form-data><input type=file name=image /><input type=submit /></form></body></html>'
###############################################################################
if __name__ == "__main__":
app.run(use_debugger=True, use_reloader=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment