5

I'm trying to use s3 to store the users' upload files, I use django storages

pip install django-storages

Added it to my INSTALLED_APPS

INSTALLED_APPS = (

...

'storages',

)

set variables in settings.py

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

AWS_ACCESS_KEY_ID = '#################'

AWS_SECRET_ACCESS_KEY = '#######################'

AWS_STORAGE_BUCKET_NAME = 'mybucketname'

I have installed boto

sudo pip install boto

dyld: DYLD_ environment variables being ignored because main executable (/usr/bin/sudo) is setuid or setgid

Requirement already satisfied (use --upgrade to upgrade): boto in /Library/Python/2.7/site-packages/boto-2.9.0_dev-py2.7.egg

Cleaning up...

When I save the item, the debug page of django jumps out,

Could not load Boto's S3 bindings.

See https://github.com/boto/boto

Any ideas? (I use mac os x 10.8.3)

Community
  • 1
  • 1
CodingCat
  • 80
  • 7
  • possible duplicate of [Error "Could not load Boto's S3 bindings."](http://stackoverflow.com/questions/10574834/error-could-not-load-botos-s3-bindings) – Marat Jan 24 '14 at 13:17

1 Answers1

0

create a bash script: install_latest_boto.sh:

#install latest boto from source
cd /home/ubuntu/
sudo mkdir boto_temp
cd boto_temp
sudo git clone git://github.com/boto/boto.git
cd boto
sudo python setup.py install 

on Django's settings - the django default storage will be s3:

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_S3_FILE_OVERWRITE = False

on your models.py:

class MyBaseModel(models.Model):
    class Meta:
        abstract = True

    @staticmethod
    def get_upload_path(instance, filename):
        if hasattr(instance, 'get_upload_folder'):
            return os.path.join(instance.get_upload_folder(), filename)
        else:
            raise Exception('Upload Folder is missing')

class User(MyBaseModel):
    name = models.CharField(max_length=100) 
    email = models.EmailField(max_length=255, unique=True)
    image = models.ImageField(upload_to=MyBaseModel.get_upload_path, default=None, blank=True, max_length=200)

    def get_upload_folder(self):
        upload_folder = 'users/images/orig'
        return upload_folder
Amit Talmor
  • 7,174
  • 4
  • 25
  • 29