NSTJ
NSTJ

Reputation: 3888

Can I upload an ImageField directly from the Django admin to S3 using django-storages and boto?

I'm attempting to upload the image component of an ImageField directly to S3 through the django admin when I create a record. Is it possible to achieve this directly by simply specifying the AWS S3 url for static files in

MEDIA_URL = 'https://s3.amazonaws.com/myapp/media/'

and specifying boto in:

STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

or is it necessary to run the collectstatic command/upload using a homegrown form to submit to AWS. django-storages docs give no real indication of whether this is possible and preliminary attempts to upload images to S3 using admin have not yielded results.

Upvotes: 2

Views: 2980

Answers (1)

Marius Grigaitis
Marius Grigaitis

Reputation: 2520

I think staticfiles != media files. But I also think you can define storage for media file too, so auto upload to S3 should be a possibility.

https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.FileField.storage https://docs.djangoproject.com/en/dev/topics/files/ https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-DEFAULT_FILE_STORAGE

Upvotes: 3

Related Questions