Reputation: 45
I am using GCP to serve static files. But Django is using a signed URL which contains expire googleserveraccessId and etc. Please tell me how I can use an unsigned URL which only has a path. my settings.py file
DEFAULT_FILE_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage'
STATICFILES_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage'
GS_BUCKET_NAME = 'xyzxyzxyx'
GS_CREDENTIALS = service_account.Credentials.from_service_account_file(
"project/filename.json"
)
STATICFILES_DIRS =[
os.path.join(BASE_DIR, 'myapp/static')
]
STATIC_URL = '/static/'
STATIC_ROOT = 'https://storage.googleapis.com/{}/static/'.format(GS_BUCKET_NAME)
MEDIA_URL = 'https://storage.googleapis.com/{}/'.format(GS_BUCKET_NAME)
MEDIA_ROOT = 'https://storage.googleapis.com/{}/'.format(GS_BUCKET_NAME)
Upvotes: 0
Views: 424
Reputation: 553
Add these two strings to your settings.py:
GS_QUERYSTRING_AUTH = False
GS_DEFAULT_ACL = None
Upvotes: 0
Reputation: 81464
If you want do not want to use authorization or signed urls, make the bucket or objects public and use the following URL format:
https://storage.googleapis.com/BUCKET_NAME/OBJECT_NAME
For details on making objects public via the Google Cloud Console:
Making individual objects publicly readable
You can also make objects public with the CLI:
gsutil acl ch -u AllUsers:R gs://BUCKET_NAME/OBJECT_NAME
Before trying those commands first check if this is supported for your bucket configuration:
If the above verfication is true use this link to make the entire bucket public:
Making all objects in a bucket publicly readable
Make sure that there is nothing in the bucket that should be private.
Upvotes: 1