## TL;DR

If two writers can touch the same object, set a generation precondition. generation\_match\_precondition=0 means "only write if the object does not exist": `python blob.upload\_from\_filename("/local/file", if\_generation\_match=0) ` Use the object's generation number instead of 0 for read-modify-write safety.

## Steps

1. ```python
from google.cloud import storage
client = storage.Client(project="[PROJECT-ID]")
bucket = client.bucket("[BUCKET]")
blob = bucket.blob("path/to/object")
blob.upload_from_filename("/local/file")
```

2. Things that bite agents:

3. Overwrite races. If two writers can touch the same object, set a generation precondition. generation_match_precondition=0 means "only write if the object does not exist":

```python
blob.upload_from_filename("/local/file", if_generation_match=0)
```

4. Use the object's generation number instead of 0 for read-modify-write safety.

5. Large files. The library does resumable uploads automatically, but on flaky networks set a longer timeout and chunk size rather than retrying blindly.

6. Uniform bucket-level access. If the bucket enforces it (and new buckets should), object ACLs are ignored completely. Do not try to set per-object ACLs; grant IAM roles on the bucket instead (roles/storage.objectViewer and friends).

7. Signed URLs are a separate concern from uploads. Generating one from a service account key is easy; generating one from metadata-server ADC needs iam.serviceAccounts.signBlob on the SA, and it fails otherwise. Do not conflate "I can upload" with "I can sign".

8. Bucket names are global. A 403 on create can mean the name is taken in another project, not that you lack permission. Pick distinctive names.

9. Verify: after upload, `blob.exists()` or `gcloud storage ls gs://[BUCKET]/path/` and check the object's generation matches what you expect.

## When to use

You are seeing this: Basic upload: ``python from google.cloud import storage client = storage.Client(project="[PROJECT-ID]") bucket = client.bucket("[BUCKET]") blob = bucket.blob("path/to/object") blob.upload\_from\_filename("/local/file") ` Things that bite agents: 1. Use this skill when you run into "GCS Python uploads done right: preconditions, retries, and uniform access".

## When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

## Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

## Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
