# The upload script: one file, any tool

What hematite's upload script does: it uploads the image it's given, prints the link and copies it. How to run it, what it needs, what it says when it fails.

Screenshot tools that have no upload of their own can still send each capture to hematite: they run hematite's upload script with the capture's path, and the script uploads it and prints its link. [Flameshot](https://hematite.gg/docs/uploaders/flameshot), [ksnip](https://hematite.gg/docs/uploaders/ksnip) and [Greenshot](https://hematite.gg/docs/uploaders/greenshot) have their own guides; any other tool that runs a command with a file's path works the same way.

## Get it

On [Settings → Uploaders](https://hematite.gg/settings/uploaders), press **Download script** beside the tool you use. Each download is the same script with a new upload token in it, listed under that tool's name. It comes in two forms:

| File                  | For                                                        | Needs                                                               |
| --------------------- | ---------------------------------------------------------- | ------------------------------------------------------------------- |
| `hematite-upload.sh`  | macOS and Linux (Flameshot, ksnip)                         | `sh` and `curl`, which both systems have                            |
| `hematite-upload.ps1` | Windows (Greenshot)                                        | Windows PowerShell 5.1, in every Windows 10 and 11, or PowerShell 7 |
| `hematite-upload.cmd` | Windows, for ksnip, which starts a `.cmd` but not a `.ps1` | The same: its first lines start the PowerShell script under them    |

## Run it

```sh label="macOS and Linux"
sh hematite-upload.sh screenshot.png
```

```powershell label="Windows"
powershell -NoProfile -ExecutionPolicy Bypass -File hematite-upload.ps1 screenshot.png
```

- **Done,** it prints the link and nothing else, and copies it: with `pbcopy` on a Mac, `wl-copy` on Wayland, `xclip` or `xsel` on X11, whichever is there; on Windows, to the clipboard.
- **It takes** a PNG, JPEG, GIF or WebP of up to 16 MB, told by the file's first bytes, not its name.
- **`-` instead of a file** uploads the image on standard input: `flameshot gui --raw | sh hematite-upload.sh -`.
- **Flameshot's script** captures first when it's run without a file.

Its uploads take your [upload settings](https://hematite.gg/settings/upload) and their link follows your [link settings](https://hematite.gg/docs/guides/share-links), as every upload's does.

## The token inside

The script holds an upload token, which can upload to your account and do nothing else, for 90 days from the download. Keep the file to yourself: on macOS and Linux, `chmod 700 hematite-upload.sh` lets only you read it. The script never prints the token, and hands it to `curl` on standard input rather than on its command line, where anyone on the computer could read it. If the file gets out, remove its token on [Settings → Uploaders](https://hematite.gg/settings/uploaders) or [Settings → Security](https://hematite.gg/settings/security), and download a new script.

## When it fails

It says why on standard error, starting `hematite:`, and ends with 1. Run it by hand in a terminal to read it.

| It says                                          | What to do                                                                      |
| ------------------------------------------------ | ------------------------------------------------------------------------------- |
| hematite refused the upload key                  | The token expired or was removed: download a new script                         |
| Your storage is full                             | Delete something, or see [pricing](https://hematite.gg/pricing)                                    |
| … isn't a PNG, JPEG, GIF or WebP                 | Save captures as PNG or JPEG                                                    |
| … is 18 MB; hematite takes images of up to 16 MB | Save a smaller capture, or as JPEG                                              |
| Too many uploads at once                         | Wait a moment: uploads go at 60 a minute |
| Couldn't reach hematite                          | Check the connection; the rest of the line says what `curl` or Windows met      |

[API errors and rate limits](https://hematite.gg/docs/developers/errors) has every answer the API can give.
