`$saveUploadedImage` keeps the image a user uploaded in a modal. The link Discord gives for an upload stops working after 24 hours; this function downloads the image, stores it in the files of the bot (the same storage as `$fileUpload`) and returns a permanent link to it.

Put `$defer` before it: a large image can take longer than the 3 seconds Discord allows for an answer.

## Parameters

| Parameter | Description |
|---|---|
| `fieldID` | Required. The custom ID of the upload field of the modal (`$addImageUpload[]`, `$addModalFileUpload[]`). When several files were sent, the first one is saved. |
| `path` | Optional. Where to store the image, for example `avatars/$authorID.png`. By default `uploads/<fieldID>-<file id>.<png, jpeg, gif or webp>`. Writing to an existing path replaces the file. |

## Return value

The permanent link of the stored image. It works until the file is deleted with `$fileDelete[]`.

## Errors

Catch them with `$try`.

- `file_upload_missing`: the modal sent no file for this field.
- `file_not_image`: the file is not a PNG, JPEG, GIF or WebP image. The check reads the content of the file, not its name.
- `file_too_large`: the image is larger than 10 MB.
- `file_download_failed`: the file could not be downloaded from Discord.
- `file_quota_exceeded`: the storage of the account is full.
- `files_unavailable`: the bot has no file storage (phone, sandbox).
- `file_url_unavailable`: a bot that runs locally on desktop stores the image but has no public link.

## Examples

```bdfd
$defer
$try
  $var[link;$saveUploadedImage[avatar;avatars/$authorID.png]]
  $setUserVar[avatar;$var[link]]
  Your picture is saved.
$catch
  $if[$error[message]==file_not_image]
    Please send a PNG, JPEG, GIF or WebP image.
  $else
    I could not save your picture ($error[message]).
  $endif
$endtry
```

## Notes

- The images count against the storage quota of the account, like every file of the bot. `$fileCount[uploads/]` tells how many are stored, `$fileList[uploads/]` lists them, `$fileDelete[]` removes one.
- In JavaScript: `await bc.files.saveUpload(interaction.fields.getUploadedFiles('avatar').first(), 'avatars/me.png')`.
