# Storage

Uploaded files go through Spatie Media Library on named Flysystem disks (PLAN › Media storage).

| Disk | Where | Used for |
| --- | --- | --- |
| `media` | `storage/app/public/media`, served at `/storage/media` | public media on the server |
| `private` | `storage/app/private/files`, not served | private files on the server |
| `s3-media` | the bucket, under `media/`, URL = public address + `/media` | public media in the bucket |
| `s3-private` | the private bucket (or the same one), under `private/` | private files in the bucket |

`Platform\Storage\S3Disks::apply()` runs once the app has booted: it reads `StorageSettings` (group `storage`, keys
encrypted) and defines the two `s3-*` disks whenever a bucket is set up, so media already moved there keeps working
after switching back. The chosen driver sets `media-library.disk_name` (where new uploads go) and
`syncshop.storage.private_disk` (for invoices and other private files). A fresh shop, or a database that can't be
read, keeps the server's disks.

Each media record stores its disk, so a move never breaks a link: `MoveMediaFile` copies the original, its
conversions and responsive images, checks each file's size on the target, then updates `disk` and
`conversions_disk`, and only then deletes the old copies. `media:move --to=s3|local [--queue] [--keep]` runs it for
every item not yet on the target disk; `--queue` and the admin button queue one `MoveMedia` job per item.

The S3 disks have no `visibility` unless *ACL public-read* is on: providers such as R2 refuse ACL headers, and the
bucket policy decides. They use `throw => true`, so a refused write is an error, not a silent `false`.

`TestStorageConnection` builds the disks from unsaved form values and writes, reads and deletes a file on both,
fetches the public file over HTTP (a warning if it fails) and fails if the private file can be read at the public
address. Those two HTTP requests go only to public addresses: `PublicAddress` resolves the host and refuses it if any
address is loopback, private, link-local or reserved; the request is pinned to the checked address (`CURLOPT_RESOLVE`)
and never follows redirects, so the test can't be aimed at the server's own network. A public address on a private
network is reported as not checked. The S3 endpoint itself isn't restricted, because a MinIO on the local network is
a normal setup. `StorageErrors` turns the S3 error code into a sentence; keys never appear in messages, and the form's
`access_key`/`secret_key` are in the exception handler's `dontFlash` list.

Tests replace the `s3` driver with local folders (`Storage::extend('s3', …)`) and fake the HTTP checks; see
`tests/Feature/Platform/StorageTest.php`.
