2

I have created a social media app using Django and Vue. My frontend is hosted on Vercel (which is working just fine) and my backend is hosted on DigitalOcean's App Platform (I am NOT using a droplet) and connected to my Github repo. Everything about my app is functioning perfectly well except for my user-uploaded media files. I am using django-storages (S3Boto3Storage) for this purpose and have followed all of the instructions in several tutorials (such as this one, this one, and the documentation). I have even gotten my static files up on DigitalOcean Spaces using this process (as in, when I check my bucket, the correct files appear to be there), but every time I try to deploy, it fails at python manage.py collectstatic. I've tried changing literally every single element of my settings.py file pertaining to static and media variables, creating a new Spaces bucket, messing with STATICFILES_DIRS and STATIC_ROOT, and updating/changing my App-level environment variables in the DigitalOcean App Platform UI. However, I keep getting a few different errors that I've been having trouble debugging.

Sometimes I get this error: ?: (staticfiles.W004) The directory '/workspace/backend/static' in the STATICFILES_DIRS setting

And other times I get this error: botocore.exceptions.ClientError: An error occurred (404) when calling the HeadObject operation: Not Found

Here are the settings in my settings.py file:

    AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID')
    AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY')
    AWS_STORAGE_BUCKET_NAME = 'rec-room-media'
    AWS_DEFAULT_ACL = 'public-read'
    AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400'}

Note: I have tried using both of the following for my endpoint URL:

    AWS_S3_ENDPOINT_URL = 'https://rec-room-media.nyc3.digitaloceanspaces.com'
    # AWS_S3_ENDPOINT_URL = 'https://nyc3.digitaloceanspaces.com'

Note: I've tried using both STATIC ROOT and STATICFILES_DIRS but neither have worked

    # STATIC_ROOT = os.path.join(BASE_DIR, 'static')
    STATICFILES_DIRS = [
        os.path.join(BASE_DIR, 'static'),
    ]
    AWS_LOCATION = 'static'
    STATIC_URL = f'https://{AWS_S3_ENDPOINT_URL}/{AWS_LOCATION}/'
    
    AWS_MEDIA_LOCATION = 'media'
    PUBLIC_MEDIA_LOCATION = 'media'
    MEDIA_URL = f'https://{AWS_S3_ENDPOINT_URL}/{AWS_MEDIA_LOCATION}/'

Note: I saw in the docs that the following two lines were deprecated as of Django 4.2, so I tried using the STORAGES variable as well

    STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
    DEFAULT_FILE_STORAGE = 'backend.storage_backend.MediaStorage'
    # STORAGES = {
    #     'staticfiles': {
    #         'BACKEND': 'storages.backends.s3boto3.S3Boto3Storage',
    #     },
    #     'default': {
    #         'BACKEND': 'backend.storage_backend.MediaStorage',
    #     },
    # }

Any help would be appreciated greatly!! I feel like I'm probably missing something deeply obvious.

1
  • i am currently experiencing same issue as well and i've been unable to resolve it using django 4.2. Were you finally able to resolve it. Commented Dec 17, 2023 at 6:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.