This backend doesn't support absolute paths Django Google Storage

I have a Django app in Compute Engine. I set up a Google Cloud Storage as storage for my media files. In one endpoint, you can request for the file information including the file path. When I POST for this endpoint it returns:

This backend doesn't support absolute paths.

For simplicity my view for the endpoint look like this:

class FilesView(APIView):
    permission_classes = (permissions.AllowAny,)

    def post(self, request):
        path = layer.file.path
        response_message = {'file': path }
        return Response(response_message, status.HTTP_200_OK)

I have done the following:

  1. Create a service account and download the JSON.
  2. Configure it to my Django settings.
  3. I added the service account to the permissions in the bukcet i.e. set as Storage Admin.
  4. I added allUsers to have permission: Storage Legacy Object Reader.
  5. I changed the bucket from Uniform to Fine-grained.

Here is in my settings:

DEFAULT_FILE_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage'
STATICFILES_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage'
GS_BUCKET_NAME = 'sample-bucket'
GCP_CREDENTIALS = os.path.join(BASE_DIR, 'sample-bucket-credentials.json')
GS_CREDENTIALS = service_account.Credentials.from_service_account_file(GCP_CREDENTIALS)
Back to Top