[Python] Django Cloud Storage NoSuchKey

Discussão em 'Python' iniciado por Stack, Fevereiro 20, 2025.

  1. Stack

    Stack Membro Participativo

    I deploy a Django/React project with GKE, Cloud SQL as DB, Cloud Storage for static file. When I trying upload files(both by Django admin and API), the url I get always tells me

    This XML file does not appear to have any style information associated with it. The document tree is shown below.
    <Error>
    <Code>NoSuchKey</Code>
    <Message>The specified key does not exist.</Message>
    <Details>No such object: my-bucket/media/uploads/01.JPG</Details>
    </Error>


    I tryed directly upload file in GCP console and file can be visited. Also when I use

    gsutil cp .gitignore gs://my-bucket/media/


    file can be visited.

    below are my settings.py


    # Static files (CSS, JavaScript, Images)
    # https://docs.djangoproject.com/en/5.1/howto/static-files/

    DEFAULT_FILE_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage'
    STATICFILES_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage'

    GS_BUCKET_NAME = 'my-bucket'
    GS_MEDIA_BUCKET_NAME = 'my-bucket'
    GS_DEFAULT_ACL = 'publicRead'
    GS_FILE_OVERWRITE = False

    # STATIC_ROOT = '/app/static'
    STATIC_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/static/"
    MEDIA_URL = f"https://storage.googleapis.com/{GS_MEDIA_BUCKET_NAME}/media/"


    and deployment.yaml

    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: app
    spec:
    replicas: 2
    selector:
    matchLabels:
    app: app
    template:
    metadata:
    labels:
    app: app
    spec:
    serviceAccountName: my-service-account
    containers:
    - name: app
    image: asia-east1-docker.pkg.dev/my-project-id/app/backend:latest
    ports:
    - containerPort: 8000
    env:
    - name: DB_USER
    - name: DB_PASSWORD
    - name: DB_NAME
    - name: DB_HOST
    - name: DB_PORT
    resources:
    requests:
    memory: "512Mi"
    cpu: "500m"
    limits:
    memory: "1Gi"
    cpu: "1"
    - name: cloud-sql-proxy
    image: gcr.io/cloud-sql-connectors/cloud-sql-proxy:latest
    args:
    volumeMounts:
    - name: cloudsql
    mountPath: /cloudsql
    securityContext:
    runAsNonRoot: true
    resources:
    requests:
    memory: "256Mi"
    cpu: "100m"
    limits:
    memory: "512Mi"
    cpu: "250m"
    volumes:
    - name: cloudsql
    emptyDir:
    medium: Memory


    What I want is that when I upload by API or Django admin, I can find files in my bucket.

    Continue reading...

Compartilhe esta Página