0

Currently I serve the staticfiles of a website on a S3 AWS bucket. I would like to be able to send the files the user uploads to a different bucket. I have these settings:

settings.py

if AMAZON_S3:
    DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
    AWS_ACCESS_KEY_ID = os.environ['AWSAccessKeyId']
    AWS_SECRET_ACCESS_KEY = os.environ['AWSSecretKey']
    AWS_STORAGE_BUCKET_NAME = os.environ['AWS_STORAGE_BUCKET_NAME']
    S3_URL = 'http://%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME
    STATIC_URL = S3_URL
    STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
    MEDIA_URL = 'http://%s.s3.amazonaws.com/' % "someotherbucket"  #!! Doesn't work

The model with the FileField works correctly, but anyway I'll paste it here, it looks like this:

def send_file(instance, filename):
    date = datetime.today()
    return "/".join([fecha.strftime("%d_%m_%Y"), filename])

class Booking(models.Model):
    ...
    file_a = models.FileField(upload_to=send_file)
    ...

The staticfiles are being served correctly, but the files the user uploads still go to the same bucket where the staticfiles are. How can I change that?

Alejandro Veintimilla
  • 10,743
  • 23
  • 91
  • 180

0 Answers0