# fs.file.put

Write one file into a project store

# fs.file.put

```
fs.file.put [--from FILE] [--text TEXT] [--encoding text|base64] [--value JSON] [--accept image|pdf|csv|json|glb|audio|video|archive…] [--max-size SIZE] [--store TEXT] [--folder TEXT] [--filename TEXT] [--path TEXT] [--on-conflict error|skip|overwrite] → file
```

Write one file into a project store. Exactly one source: `--from` a file the run holds — an upload (`{{ $trigger.files.photo }}`), a FileRef from any store, a byte envelope, or a store key — checked by its content (the claimed type must agree, `--accept` must allow it, default `image`, and the stored extension follows the detected type); `--text` written as given (`--encoding base64` decodes it to bytes first); or `--value`, any JSON value written as JSON (a string is written as its text). Every source is refused above `--max-size` (default 10MB). Writes under `--folder` (default `uploads`) as a generated name, as `--filename`, or at an exact `--path`; a named file that exists is an error unless `--on-conflict` says otherwise. Adds `file` — the durable FileRef (`ref`, `store`, `mime`, `kind`, `size`, `sha256`, `origin: fs.file.put`, `trust`) — and keeps the rest of the payload, so `input.webhook.body.caption` from the same form is still there. Store `file.ref` in a row, never a URL.

## Flags

- `--from`: The file to write: an upload, a FileRef, a byte envelope or a store key, usually `{{ $trigger.files.<field> }}`.
- `--text`: Content written as given.
- `--encoding`: How --text is read: text (default) or base64, decoded to bytes first.
- `--value`: Any JSON value, written as JSON; a string is written as its text.
- `--accept`: A file kind --from may be, by content (repeat; default: image).
- `--max-size`: The largest file written, with its unit (default: 10MB).
- `--store`: The project store to write to: `local`, or the id of an `s3` credential. Saved explicitly when the pipeline is registered (default: the project's default store at that moment)
- `--folder`: Destination folder (default: uploads).
- `--filename`: Destination name (default: a generated name); for --from, a missing extension is the detected one.
- `--path`: Exact destination key; overrides --folder and --filename.
- `--on-conflict`: When the target already exists: overwrite, skip or error (default: error)

## Examples

### Keep an uploaded photo

```
| fs.file.put --from "{{ $trigger.files.photo }}" --folder uploads --accept image --max-size 10MB
```

Then `sekejap.query.run --write --param "1={{ $trigger.body.caption }}" --param "2={{ input.file.ref }}" -- "INSERT INTO photos (caption, path) VALUES ($1, $2)"`. `file` is a FileRef, so `fs.image.thumbnail --from "{{ input.file }}"` and a `--preview image` take it as it is.

Input:

```json
{
  "webhook": {
    "body": {
      "caption": "Sunset"
    },
    "files": {
      "photo": {
        "__zf_type": "file_ref",
        "backend": "zebfs",
        "store": "local",
        "ref": "tmp/runs/r1/files/IMG_1.jpg",
        "filename": "IMG_1.jpg",
        "mime": "image/jpeg",
        "kind": "image",
        "size": 182331,
        "sha256": "sha256:…",
        "lifecycle": "temporary",
        "origin": "webhook",
        "trust": "untrusted"
      }
    }
  }
}
```

It answers:

```json
{
  "webhook": {
    "body": {
      "caption": "Sunset"
    },
    "files": {
      "photo": {
        "__zf_type": "file_ref",
        "backend": "zebfs",
        "store": "local",
        "ref": "tmp/runs/r1/files/IMG_1.jpg",
        "filename": "IMG_1.jpg",
        "mime": "image/jpeg",
        "kind": "image",
        "size": 182331,
        "sha256": "sha256:…",
        "lifecycle": "temporary",
        "origin": "webhook",
        "trust": "untrusted"
      }
    }
  },
  "file": {
    "__zf_type": "file_ref",
    "backend": "zebfs",
    "store": "local",
    "ref": "uploads/3f9c….jpg",
    "filename": "3f9c….jpg",
    "mime": "image/jpeg",
    "kind": "image",
    "size": 182331,
    "sha256": "sha256:…",
    "lifecycle": "durable",
    "origin": "fs.file.put",
    "trust": "untrusted"
  }
}
```

### Write a report

```
| fs.file.put --value "{{ input.report }}" --folder exports --filename report.json
```

Input:

```json
{
  "report": {
    "total": 3
  }
}
```

It answers:

```json
{
  "report": {
    "total": 3
  },
  "file": {
    "__zf_type": "file_ref",
    "backend": "zebfs",
    "store": "local",
    "ref": "exports/report.json",
    "filename": "report.json",
    "mime": "application/json",
    "kind": "json",
    "size": 11,
    "sha256": "sha256:…",
    "lifecycle": "durable",
    "origin": "fs.file.put",
    "trust": "generated"
  }
}
```

### Write text

```
| fs.file.put --text "{{ input.csv }}" --folder exports --filename totals.csv --on-conflict overwrite
```
