← Debugging Guides

阅读中文版本

Google Cloud Storage — blob not found on download

GCS returns 404 Not Found because the blob name or bucket is incorrect, or the blob is in a different project or location.

beginnerdebugginggcsstorage

Symptoms

  • error: The specified blob does not exist
  • Download works for some blobs but not others
  • The blob appears in the console but the SDK returns 404

Possible causes

  • The blob name has a typo or wrong path prefix
  • The SDK uses a different project or service account than expected
  • The blob was deleted or never uploaded to this bucket

Diagnosis steps

List blobs in the bucket

gcloud storage ls gs://mybucket/path/

Interpretation

If the blob is not listed, it does not exist at that path.

Check the SDK credentials and project

gcloud auth list && gcloud config get-value project

Interpretation

Confirm the SDK uses the same project as the console.

Root cause

The blob does not exist at the specified path in the bucket, or the SDK is authenticated to a different project where the blob is not present.

Fix

Verify the blob name and bucket, ensure the SDK uses the correct project and credentials, and upload the blob if it is missing.

Verify the fix

Download the blob and confirm the content matches; verify a non-existent blob returns 404.

Symptom walkthrough

GCS returns 404 Not Found because the blob name or bucket is incorrect, or the blob is in a different project or location. The error appears in production but may not surface in local development because the conditions that trigger it depend on the deployment environment or runtime configuration. Understanding the full symptom set helps distinguish this issue from similar errors.

Diagnosis in practice

Follow the diagnosis steps in the frontmatter to isolate the cause. Each step includes a command and an interpretation of the output. The goal is to narrow down whether the issue is in the configuration, the runtime, or the application code. Reproduce the error in a minimal setup before applying a fix.

Root cause

The blob does not exist at the specified path in the bucket, or the SDK is authenticated to a different project where the blob is not present.

Fix

Verify the blob name and bucket, ensure the SDK uses the correct project and credentials, and upload the blob if it is missing. After applying the fix, monitor the system to confirm the error does not recur under load or in different environments.

Verification

Download the blob and confirm the content matches; verify a non-existent blob returns 404. If the verification passes, the fix is confirmed; if not, re-examine the diagnosis steps for missed contributing factors.

Diagnostic commands

Run these commands to reproduce and diagnose the issue:

gcloud storage ls gs://mybucket/path/
gcloud auth list && gcloud config get-value project