> ## Documentation Index
> Fetch the complete documentation index at: https://docs.occtoo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# occtoo media

> Upload files and folders to media sources, give them properties, and convert images

Use `occtoo media` to upload files into a media source, give them properties from a spreadsheet, look at and delete assets, and convert images.

## Upload files

```bash theme={null}
occtoo media upload hero.jpg --to productImages
occtoo media upload *.jpg --to productImages/campaigns/spring
occtoo media upload ./photos --to productImages --dry-run
occtoo media upload ./photos
```

* `--to` names a media source, optionally followed by a folder: `<SOURCE>/<FOLDER>`. Leave it out in a terminal to pick the source and folder from a list.
* A folder is uploaded with everything in it. `photos/shoes/front.jpg` goes into the folder `photos/shoes` below the destination. Folders the source doesn't have are created. Hidden files are left out.
* The entry key of a file is its name without the extension, so `sku-123.jpg` becomes the entry `sku-123`. Characters other than letters, digits, `_` and `-` become `-`.

Uploading again is safe. A file whose name and size match what is stored is skipped, a changed file replaces what is there, and a run that failed halfway continues where it stopped.

| Flag | Description |
| - | - |
| `--to <SOURCE[/FOLDER]>` | Where to upload to |
| `--key <KEY>` | Entry key for the file, when you upload a single one |
| `--key-from <name\|path>` | What entry keys are made from. `name` (default): `photos/shoes/front.jpg` gets `front`. `path`: it gets `photos-shoes-front` |
| `--flatten` | Put every file straight into the destination folder instead of mirroring local folders |
| `--force` | Upload again even when a file of the same name and size is already stored |
| `--dry-run` | Show what would be uploaded, replaced and skipped, without changing anything |
| `--metadata <FILE>` | A CSV or Excel file that gives files their properties, and optionally their entry keys |
| `--set <PROPERTY=VALUE>` | Set this property on every file. Repeat for several |

## Give files properties

Files get their properties from a metadata file: CSV or Excel, with one row per file. `occtoo media manifest` writes one for you to fill in by hand, in a spreadsheet or with a script:

```bash theme={null}
occtoo media manifest ./photos --to productImages --languages en,sv > photos.csv
occtoo media upload ./photos --to productImages --metadata photos.csv --dry-run
occtoo media upload ./photos --to productImages --metadata photos.csv
```

```csv theme={null}
file,key,title(en),title(sv),photographer,tags
shoes/front.jpg,sku-1-front,Front view,Framifrån,Ann Lee,shoe|summer
hero.jpg,,Spring hero,,,campaign
```

* `file` names a file by its name, or by as much of its path as tells it apart from the others.
* `key`, when present, sets the entry key of the file.
* Every other column is a property of the source, named and read as in [`occtoo sources import`](https://docs.occtoo.com/cli/commands/sources#how-values-are-read). Use `title(en)` for a value in one language.
* An empty cell leaves a value as it is.

To give every file the same value, use `--set`:

```bash theme={null}
occtoo media upload ./photos --to productImages --set photographer="Ann Lee"
```

A row in the metadata file wins over `--set`, and an empty value such as `--set title=` clears the property. The CLI checks everything before it sends the first file. A file that is already stored is not sent again, but still gets its properties.

`media manifest` writes CSV to stdout. The `key` column holds the entry key each file would get. Change it to give a file another key.

| Flag (`manifest`) | Description |
| - | - |
| `--to <SOURCE>` | The media source the files will go to. Leave it out in a terminal to pick from a list |
| `--key-from <name\|path>` | What entry keys are made from, as for `upload` |
| `--languages <LANGUAGES>` | Add a column per language for every property that has a value per language |

## Show and delete assets

```bash theme={null}
occtoo media show productImages hero
occtoo media delete productImages hero sku-123 --yes
```

`show` prints the state and public address of each asset. `delete` removes assets and the files behind them. Both take a media source id and one or more entry keys.

## Convert images

```bash theme={null}
occtoo media convert hero.jpg --preset web-large --preset thumbnail
occtoo media convert hero.jpg --size 1200 --format webp --quality 80
occtoo media convert hero.png --size 800 --mode fill-background --padding 5 --background FFFFFF
```

Converts an image with one or more stored presets, or with parameters you give, and saves the result next to it. The result is named `<name>-<preset>.<format>`, or `<name>-converted.<format>` without a preset.

| Flag | Description |
| - | - |
| `--preset <PRESET>` | Convert with this preset. Repeat for several results |
| `--size <SIZE>` | Longer side of the result in pixels, from 1 to 8000. Converts without a preset |
| `--mode <MODE>` | How the image is placed on the canvas. `fit` (default) scales to fit. `fill-background` fits inside the canvas minus padding and fills the rest. `crop` fills the canvas and crops from the center. `auto` crops when the image and canvas have the same orientation, and fits otherwise |
| `--ratio <RATIO>` | The canvas as `width:height`. Default `1:1` |
| `--format <FORMAT>` | `jpg`, `png` or `webp`. Default `webp` |
| `--quality <QUALITY>` | From 1 to 100. Default `85` |
| `--padding <PADDING>` | Padding on each side in percent, from 0 to 49. Needed with `--mode fill-background` |
| `--background <HEX>` | Color behind transparent areas and padding, as six hex digits, such as `FFFFFF` |
| `--out <FOLDER>` | Folder to save the results in. Default: the folder of the image |

## Conversion presets

A preset stores conversion parameters, so you can convert by name.

```bash theme={null}
occtoo media presets list
occtoo media presets show web-large
occtoo media presets create --file preset.json
echo '{"displayName": "Web XL"}' | occtoo media presets edit web-large
occtoo media presets delete web-large --yes
```

JSON for `create`. `paddingPercent` and `background` are optional:

```json theme={null}
{
  "id": "web-large",
  "displayName": "Web large",
  "parameters": {
    "mode": "Fit",
    "targetSize": 1600,
    "aspectRatio": "4:3",
    "outputFormat": "Webp",
    "quality": 85
  }
}
```

* Modes: `Fit`, `FillBackground` (needs `paddingPercent`), `Crop`, `Auto`.
* Formats: `Jpg`, `Png`, `Webp`.

For `edit`, both `displayName` and `parameters` are optional. When you give `parameters`, they replace all current parameters.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.