0

I have a django project with aws s3 used to store images the website has.

The website allows users to upload their own image, and that works just fine. When I add a model instance with a jpg, the file is uploaded to aws and can be viewed in the admin panel.

The problem is, however, is that I also used fixtures to load in pre defined objects with images, but whenever I interact with the preloaded fixtures in the database, I get a 400 error.

Screenshot of databse The first object named "Test" was manually added, and all of the other objects below that one were added from the fixture. Test opens normally but all of the other objects give a 400 error.

I tried changing my region in the aws bucket but that did not help.

Here is an example of a couple of fixtures

{
    "model": "transfer.Workout",
    "fields":{
        "title": "Lat Pull Downs",
        "notes": "dont move your back at all, pull towards chest, retract shoulder blades as you go down, let elbows go straight down",
        "sets": "5",
        "demonstration": "/demonstrations/back&bicep/back/latpulldowns.gif",
        "muscle": "back"
     }
},
{
    "model": "transfer.Workout",
    "fields":{
        "title": "Cable Rows",
        "notes": "keep shoulder neutral, pull towards abs, pull shoulder blades back, exhale as you pull weight in",
        "sets": "5",
        "demonstration": "/demonstrations/back&bicep/back/cablerows.gif",
        "muscle": "back"
     }
        
        
},

Here is a picture of the aws bucket

Settings:

INSTALLED_APPS = [
   'transfer.apps.TransferConfig',
   'django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles',
   'storages'
]

# AWS S3 Settings

AWS_ACCESS_KEY_ID = (insert key id here)

AWS_SECRET_ACCESS_KEY = (insert access key here)

AWS_STORAGE_BUCKET_NAME = 'workout-s3-bucket'

AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com'

AWS_DEFAULT_ACL = 'public-read'

AWS_S3_OBJECT_PARAMETERS = {
    'CacheControl': 'max-age=86400'
}

AWS_LOCATION = 'static'

AWS_QUERYSTRING_AUTH = False

AWS_HEADERS = {
    'Access-Control-Allow-Origin': '*',
}

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3StaticStorage'

STATIC_ROOT = os.path.join(BASE_DIR, 'transfer', 'static', 'travser')
STATIC_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/static/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/media/'

Thanks, apologies if I did not give enough info.

Manoj Tolagekar
  • 1,816
  • 2
  • 5
  • 22
NicholasM
  • 13
  • 1
  • 6

0 Answers0