Error uploading to a non-US Standard AWS S3 Bucket in Django application; US Standard bucket works perfectly

后端 未结 3 475
天命终不由人
天命终不由人 2021-01-15 14:48

I set up an S3 bucket in a non-US region (Singapore). When I try to upload images to it, I get a 301 (Permanently moved) error from S3. Res

相关标签:
3条回答
  • 2021-01-15 15:17
    AWS_AUTO_CREATE_BUCKET = True
    AWS_S3_HOST = 's3-eu-west-1.amazonaws.com'
    

    This works also for django-storages. Thanks @gmcc051

    0 讨论(0)
  • 2021-01-15 15:20

    "Singapore" is not a valid "region" in the sense that you need, here:

    AWS_S3_REGION = 'ap-southeast-1'
    

    http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region

    This may not be the only issue, but it should be one of the issues, at least.

    0 讨论(0)
  • 2021-01-15 15:30

    I'm using the current version of django-storages-redux and had to use the following in settings.py in order to use the Sydney S3 region.

    import boto
    from boto.s3.connection import OrdinaryCallingFormat, Location
    
    DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
    AWS_ACCESS_KEY_ID = 'XXX'
    AWS_SECRET_ACCESS_KEY = 'XXX'
    AWS_STORAGE_BUCKET_NAME = 'my.bucket.name'
    AWS_AUTO_CREATE_BUCKET = False
    AWS_S3_HOST = 's3-ap-southeast-2.amazonaws.com'
    AWS_S3_CALLING_FORMAT = 'boto.s3.connection.OrdinaryCallingFormat'
    

    Note the AWS_S3_HOST value; that is the parameter that I needed to solve the "301 (Permanently moved)" error.

    0 讨论(0)
提交回复
热议问题