Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

403 on read #903

Closed
ajeema opened this issue Jul 10, 2020 · 5 comments
Closed

403 on read #903

ajeema opened this issue Jul 10, 2020 · 5 comments

Comments

@ajeema
Copy link

ajeema commented Jul 10, 2020

I'm trying to get django-storages to work with A3 but have run into a few hurdles so I tried Google Cloud but the same issues arise. I have given full permissions and followed tutorials but am still stuck.

I'm uploading to S3 fine. The issue is trying to pull the file down or read from a file. Once the file has been uploaded I have a function to run ffprobe against the video file and parse all the video meta data into a db. however, when I try to call the video I get 403 error. I've given full permissions, I can PUT the file on S3 and or Google, I can see the files there. But when I try to read the file and run ffprobe against it I get 403. Any suggestions???

settings.py

INSTALLED_APPS += ["storages"]  
AWS_ACCESS_KEY_ID = env("DJANGO_AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = env("DJANGO_AWS_SECRET_ACCESS_KEY")
AWS_STORAGE_BUCKET_NAME = env("DJANGO_AWS_STORAGE_BUCKET_NAME")
AWS_QUERYSTRING_AUTH = False
AWS_S3_FILE_OVERWRITE = True
_AWS_EXPIRY = 60 * 60 * 24 * 7
AWS_S3_OBJECT_PARAMETERS = {
    "CacheControl": f"max-age={_AWS_EXPIRY}, s-maxage={_AWS_EXPIRY}, must-revalidate"
}
AWS_DEFAULT_ACL = None
AWS_S3_REGION_NAME = env("DJANGO_AWS_S3_REGION_NAME", default=None)
AWS_S3_CUSTOM_DOMAIN = env("DJANGO_AWS_S3_CUSTOM_DOMAIN", default=None)
aws_s3_domain = AWS_S3_CUSTOM_DOMAIN or f"{AWS_STORAGE_BUCKET_NAME}.s3-{AWS_S3_REGION_NAME}.amazonaws.com"
# STATIC
# ------------------------
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
# MEDIA
# ------------------------------------------------------------------------------
DEFAULT_FILE_STORAGE = "apps.newton.utils.storages.MediaRootS3Boto3Storage"
MEDIA_URL = f"https://{aws_s3_domain}/"

storages.py

from storages.backends.s3boto3 import S3Boto3Storage


class StaticRootS3Boto3Storage(S3Boto3Storage):
    location = "static"
    default_acl = "public-read"


class MediaRootS3Boto3Storage(S3Boto3Storage):
    location = ""
    file_overwrite = True

    def _normalize_name(self, name):
        """
        Get rid of this crap: http://stackoverflow.com/questions/12535123/django-storages-and-amazon-s3-suspiciousoperation
        """
        return name
@fleonasb
Copy link

fleonasb commented Sep 3, 2020

I have the same problem. Uploaded files to S3 get the private acl although my configuration (and bucket permissions) says public.

@Ouradze
Copy link

Ouradze commented Sep 8, 2020

See: #927 and e37912b.

@Tav0
Copy link

Tav0 commented Sep 23, 2020

So this is only fixed in AWS and not for GCP?

@yalattas
Copy link

You will need to go to S3 bucker from AWS console -> Select all objects -> Make Public. Then it will work

@jschneier
Copy link
Owner

This is a service configuration problem, not library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants