Fork me on GitHub

sqlalchemy_imageattach.stores.s3 — AWS S3 backend storage

The backend storage implementation for Simple Storage Service provided by Amazon Web Services.

sqlalchemy_imageattach.stores.s3.BASE_URL_FORMAT = 'https://{0}.s3.amazonaws.com'

(str) The format string of base url of AWS S3. Contains no trailing slash. Default is 'https://{0}.s3.amazonaws.com'.

sqlalchemy_imageattach.stores.s3.DEFAULT_MAX_AGE = 31536000

(numbers.Integral) The default max-age seconds of Cache-Control. It’s the default value of S3Store.max_age attribute.

class sqlalchemy_imageattach.stores.s3.S3Request(url, bucket, access_key, secret_key, data=None, headers={}, method=None, content_type=None)

HTTP request for S3 REST API which does authentication.

class sqlalchemy_imageattach.stores.s3.S3SandboxStore(underlying, overriding, access_key=None, secret_key=None, max_age=31536000, underlying_prefix='', overriding_prefix='')

It stores images into physically two separated S3 buckets while these look like logically exist in the same store. It takes two buckets for read-only and overwrite: underlying and overriding.

It’s useful for development/testing purpose, because you can use the production store in sandbox.

Parameters:
  • underlying (basestring) – the name of underlying bucket for read-only
  • overriding (basestring) – the name of overriding bucket to record overriding modifications
  • max_age (numbers.Integral) – the max-age seconds of Cache-Control. default is DEFAULT_MAX_AGE
  • overriding_prefix (basestring) – means the same to S3Store.prefix but it’s only applied for overriding
  • underlying_prefix (basestring) – means the same to S3Store.prefix but it’s only applied for underlying
DELETED_MARK_MIMETYPE = 'application/x-sqlalchemy-imageattach-sandbox-deleted'

All keys marked as “deleted” have this mimetype as its Content-Type header.

overriding = None

(S3Store) The overriding store to record overriding modification.

underlying = None

(S3Store) The underlying store for read-only.

class sqlalchemy_imageattach.stores.s3.S3Store(bucket, access_key=None, secret_key=None, max_age=31536000, prefix='', public_base_url=None)

Image storage backend implementation using S3. It implements Store interface.

If you’d like to use it with Amazon CloudFront, pass the base url of the distribution to public_base_url. Note that you should configure Forward Query Strings to Yes when you create the distribution. Because SQLAlchemy-ImageAttach will add query strings to public URLs to invalidate cache when the image is updated.

Parameters:
  • bucket (basestring) – the buckect name
  • max_age (numbers.Integral) – the max-age seconds of Cache-Control. default is DEFAULT_MAX_AGE
  • prefix (basestring) – the optional key prefix to logically separate stores with the same bucket. not used by default
  • public_base_url (basestring) – an optional url base for public urls. useful when used with cdn

Changed in version 0.8.1: Added public_base_url parameter.

bucket = None

(basestring) The S3 bucket name.

max_age = None

(numbers.Integral) The max-age seconds of Cache-Control.

prefix = None

(basestring) The optional key prefix to logically separate stores with the same bucket.

public_base_url = None

(basestring) The optional url base for public urls.