Skip to content

rebeccapeltz/flask-cld-upload

Repository files navigation

Flask Cloudinary Upload

Setup Virtual Env

python3 -m venv env
source env/bin/activate

Deactivate virtual env

deactivate
source env/bin/activate

Install Flask

python3 -m pip install Flask==1.1.1

Add requirements.txt

python3 -m pip freeze > requirements.txt

Run app locally

python3 app.py 

upgrade pip

usr/local/opt/[email protected]/bin/python3.9 -m pip install --upgrade pip
python3 -m pip freeze > requirements.txt

Heroku Deploy

touch Procfile
 python3 -m pip install gunicorn==20.0.4
 python3 -m pip freeze > requirements.txt

Create runtime.txt

python-3.8.1
git push heroku master
heroku open
git commit -m"...
heroku login
heroku create
heroku open

Summary of heroku deploy

  1. virtualenv env
  2. pip3 install flask
  3. pip3 install gunicorn
  4. git init
  5. add .gitignore with env and .env
  6. add Procfile with web: gunicorn --worker-class eventlet -w 1 application:app
  7. run pip3 freeze > requirements.txt
  8. git commit -m"...
  9. heroku login
  10. heroku create
  11. set up cloudinary env variables in heroku
  12. git push heroku master
  13. heroku open

Env variables

Save .env.sample as .env (it will be gitnignored). Then add your own Cloudinary credentials that you get from the Console.

touch .env
python3 -m pip install python-dotenv
python3 -m pip freeze > requirements.txt
from dotenv import load_dotenv
load_dotenv()
cloudinary.config(cloud_name = os.getenv('CLOUD_NAME'), api_key=os.getenv('API_KEY'), 
    api_secret=os.getenv('API_SECRET'))

Setting up env in heroku

Cloudinary

 python3 -m pip install cloudinary
 python3 -m pip freeze > requirements.txt

See app.js code for sample upload import and command.

Testing heroku

Using postman

CORS Support

python3 -m pip install flask-cors
python3 -m pip freeze > requirements.txt

Releases

No releases published

Packages

No packages published