etianen / django-s3-storage

Django Amazon S3 file storage.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Requesting a Short Demo project

opened this issue · comments

Hi, first off let me apologise if a lot of this is very amateurish.
Initially I was trying to get django-storages working, but I was unable to get it working for media files. I have tried to implement the code you gave in the instructions, but there were a number of issues.

The command below gave an error that the command doesn't exist
./manage.py s3_sync_meta django.core.files.storage.default_storage

from django_s3_storage.storage import S3Storage
storage = S3Storage(aws_s3_bucket_name='test_bucket')

I was wondering if that 'test_bucket' name should be named the same as it my S3 bucket, or if this is just a folder that will be created within the existing bucket?

All of the file storage settings are available for the staticfiles storage, suffixed with _STATIC. You must provide at least AWS_S3_BUCKET_NAME_STATIC. Remember to run ./manage.py collectstatic after changing your staticfiles storage backend.

Could you give an example of how AWS_S3_BUCKET_NAME_STATIC would be put into the settings? Should I just name this as anything I want?

Also when you use './manage.py' in the instructions I am assuming you mean 'python manage.py ....' Am I correct in this?

My issue with django-storages was that I was unable to upload images from the admin section directly to S3. Does this package need any additional settings to allow permissions to upload images from the admin?

I was also wondering if it would be possible to use the package in conjunction with ckeditor in the following way

from ckeditor_uploader.fields import RichTextUploadingField
storage = S3Storage(aws_s3_bucket_name='test_bucket')

class Car(models.Model):
name = models.CharField(max_length=255)
photo = models.ImageField(storage=storage)
Image/content = RichTextUploadingField(storage=storage)

Ideally I would greatly appreciate if someone could point me in the direction of a quick demo project so I can find the answers to these questions through trial and error. I have spent a rather long time building my project and since Heroku needs media served through S3 this is all an unpleasant surprise.

Kind regards,

John

I'll take a stab at a few things, not sure about ckeditor.

The command below gave an error that the command doesn't exist

Sounds like you must not have django-s3-storage installed in whatever environment you're running that command, which could be because you're running manage.py under a different environment than you were expecting. For example, if you're using virtualenv, make sure you've activated your environment before running ./manage.py. Or you can invoke the environment-specific interpreter explicitly with path/to/env/bin/python manage.py. Just make sure that your environment has django-s3-storage installed.

Could you give an example of how AWS_S3_BUCKET_NAME_STATIC would be put into the settings? Should I just name this as anything I want?

This should be the name of the s3 bucket you created. So if your bucket is named my-cool-statics you'd put:

AWS_S3_BUCKET_NAME_STATIC = 'my-cool-statics'

in your settings.py

Thanks for that, that has cleared a bit of the confusion up for me.
I definitely have the package installed. When I run pip freeze I get the following version:
django-s3-storage==0.13.0

I will sleep on it and give it another crack tomorrow. Thanks for your reply.

John

Ok that makes things easier. So just to clarify the only change I need to make in relation to the development project is add AWs credentials and DEFAULT_FILE_STORAGE? Is there any online courses or books available where I could learn about this stuff? I am finding it extremely difficult to figure out how all the pieces of this fit together, the docs I have found don't mention whether to make changes to MEDIA_URL, MEDIA_ROOT , STATIC etc which are used in development, do I need to add a boto3 class to specify where to upload the images or is this all done automatically? Also is there special permission I need to add to upload images from the admin?

I was also wondering if the code below (which i found on the net) needs to be used with the s3 package in this repo?

from storages.backends.s3boto3 import S3Boto3Storage

class StaticRootS3Boto3Storage(S3Boto3Storage):
location = "static"

class MediaRootS3Boto3Storage(S3Boto3Storage):
location = "media"
file_overwrite = False

Invalid bucket name "": Bucket name must match the regex "^[a-zA-Z0-9.-_]{1,255}$" or be an ARN matching the regex "^arn:(aws).*:s3:[a-z-0-9]+:[0-9]{12}:accesspoint[/:][a-zA-Z0-9-]{1,63}$"

I have checked and rechecked my bucket name 20 times and it just doesn't seem to make a difference. Anyway I am going to try to find another solution, unfortunately this is above my current level and I can see no way of learning how to do it. Thanks for your replies.