Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed create_all to try to get bucket first and create if one does not... #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions flask_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from flask import url_for as flask_url_for
from flask import current_app
from boto.s3.connection import S3Connection
from boto.exception import S3CreateError
from boto.exception import S3ResponseError
from boto.s3.key import Key

logger = logging.getLogger('flask_s3')
Expand Down Expand Up @@ -184,10 +184,13 @@ def create_all(app, user=None, password=None, bucket_name=None,
conn = S3Connection(user, password) # connect to s3
# get_or_create bucket
try:
bucket = conn.create_bucket(bucket_name, location=location)
bucket.make_public(recursive=True)
except S3CreateError as e:
raise e
bucket = conn.get_bucket(bucket_name)
except S3ResponseError as e:
if '404 Not Found' in str(e):
bucket = conn.create_bucket(bucket_name, location=location)
else:
raise
bucket.make_public(recursive=True)
_upload_files(app, all_files, bucket)


Expand Down