README.rst 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. Flask S3 Save Example
  2. =====================
  3. An example Flask app that uses `s3-saver <https://github.com/Jaza/s3-saver>`_, `url-for-s3 <https://github.com/Jaza/url-for-s3>`_, `flask-thumbnails-s3 <https://github.com/Jaza/flask-thumbnails-s3>`_, and `flask-admin-s3-upload <https://github.com/Jaza/flask-admin-s3-upload>`_ to store and retrieve files on Amazon S3.
  4. This app lets you upload, re-upload, and delete a single image. By changing a few lines of config, the image will be stored either locally, or in a S3 bucket of your choice.
  5. Usage
  6. -----
  7. 1. Make sure you have installed:
  8. - SQLite (3.8+ recommended)
  9. - Python 2.7+ (and virtualenv)
  10. - Pillow (Python image library)
  11. 2. Clone the flask-s3-save-example repo:
  12. ::
  13. git clone git@github.com:Jaza/flask-s3-save-example.git
  14. cd flask-s3-save-example
  15. 3. Set up a (Python 2.7) virtualenv (recommended to use with ``--system-site-packages`` option) and activate it, e.g:
  16. ::
  17. mkdir env; cd env
  18. virtualenv --system-site-packages .
  19. source bin/activate
  20. cd ..
  21. 4. Install dependencies:
  22. ::
  23. pip install -r requirements.txt
  24. 5. Create writable uploads / cache directory:
  25. ::
  26. mkdir static
  27. mkdir static/uploads
  28. chmod 777 static/uploads
  29. mkdir static/cache
  30. chmod 777 static/cache
  31. 6. Sync the database (and create a DB and DB user if necessary):
  32. ::
  33. ./project/manage.py db upgrade
  34. 7. Create a super user to log in to the app:
  35. ::
  36. ./project/manage.py createsuperuser
  37. 8. Run the development server (defaults to port 5000):
  38. ::
  39. ./project/manage.py runserver -dr
  40. 9. Access the web front-end:
  41. ::
  42. http://localhost:5000/
  43. 10. Access the admin by loging in:
  44. ::
  45. http://localhost:5000/login/?next=/admin/
  46. Configuration
  47. -------------
  48. In ``project/settings.py``, change ``USE_S3`` to ``False`` to store the image locally. If using S3, you'll need to set ``S3_BUCKET_NAME``, ``AWS_ACCESS_KEY_ID``, and ``AWS_SECRET_ACCESS_KEY`` to point to a bucket that the given AWS credentials can read / write to.
  49. More info
  50. ---------
  51. For a comprehensive guide of how to use the Flask S3 tools demonstrated here, see this blog post:
  52. http://greenash.net.au/thoughts/2015/04/storing-flask-uploaded-images-and-files-on-amazon-s3/