Cloudinary & Flask
Sign up for an account and copy your Cloudinary URL and paste it into a .env
file.

Keep Your Secrets Secret
Keep your CLOUDINARY_URL
, session secrets, and other API Keys secret. Add .env
to your .gitignore
. You don't want to push your env file to GitHub or anyone can take your API keys and use your accounts.
Dependencies
To use Cloudinary in your Flask app, you need to install two packages:
Uploading Images
To let your user upload images to your Flask app, you need an <input type="file" />
and the proper encoding type for the form: enctype=multipart/form-data
To get the image from the form in Flask use request.files
NOT request.form
:
To upload the image to Cloudinary, first import the cloudinary uploader:
Then after you get the image from the form, upload it to Cloudinary and get its url:
Cloudinary image urls look like this: https://res.cloudinary.com/dlgwpetvg/image/upload/v1678065074/g9cpesuzdqyn4hkawjcv.jpg
. Store this url in your database tables.
Fancier Cloudinary Usage
If you want to use Cloudinary's transformations on your images, store the image's public_id
:
Then transform the image before rendering your template:
Links
Last updated
Was this helpful?