multiple S3 buckets using David Larlet's S3Storage.py

53 views
Skip to first unread message

wynfred

unread,
Mar 6, 2009, 11:33:13 PM3/6/09
to Django users
David Larlet's Amazon S3 wrapper for Django seems widely used, and I'm
inclined to use it. However, there's something in the documentation
that confuses me:
http://code.welldev.org/django-storages/wiki/S3Storage

It seems as though one can only use a single bucket, in
AWS_STORAGE_BUCKET_NAME in settings.py, rather than specifying a
bucket in a FileField or ImageField field definition in models.py.

Our application needs to use distinct S3 buckets for different files
(images, feeds, etc.). Looking at the S3Storage.py code:
http://code.welldev.org/django-storages/src/af5d6b4c2d07/S3Storage.py

it seems like it might be possible to specify different S3 buckets for
different fields, but I'm not entirely clear on how one might do that.

Any suggestions to help point me in the right direction?

Thanks in advance for the excellent support here.

David Larlet

unread,
Mar 9, 2009, 10:12:10 AM3/9/09
to django...@googlegroups.com

Le 7 mars 09 à 05:33, wynfred a écrit :

You're right, it's possible but you must import directly your storage
and do not rely on django.core.files.storages.default_storage in this
case. This way you can initialize directly your storage with your
bucket name and pass the storage to the right field. Untested pseudo-
code:
s3storage = S3Storage(bucket="your-bucket-name", etc)

class YourModel:
yourimage = ImageField(storage=s3storage, etc)

Hope it helps,
David

wynfred

unread,
Apr 2, 2009, 10:23:22 PM4/2/09
to Django users
Thank you for this helpful input, David. Have not been able to focus
on this development task yet, but will soon. Your guidance is very
much appreciated.

Thanks,
Stephen
Reply all
Reply to author
Forward
0 new messages