Skip to content
Grav 2.0 is officially stable. Read the announcement →
Support

How to define environment://media ?

admin media

Started by Slebeig 2 days ago · 1 replies · 44 views
2 days ago

Grav 2.0.3, Admin2 2.0.7

Hi,

If i upload media files at /admin/media in a multisite environment having user/env/<doainname> they pop up at user/media and ignore the environment.

Than i tried to defined the "media" stream, couldn't find anything in the docs nor the forum.

YAML
schemes:
  media:
    type: Stream
    prefixes:
      '': ['environment://media']

but this didn't work.

Is ther anything undocumented, a bug or just not intend to have no media in multisite environments ;) ?

4 hours ago

Something like this:

1) Create a setup.php in your webroot (next to index.php), or at user/setup.php. Grav loads this before building the stream table, and any scheme you define here fully overrides the default:

PHP
return [
    'streams' => [
        'schemes' => [
            'media' => [
                'type' => 'Stream',
                'prefixes' => [
                    '' => ['environment://media', 'user://media'],
                ],
            ],
        ],
    ],
];

Now media://foo.jpg resolves to user/env/<hostname>/media/foo.jpg if it exists, otherwise falls back to user/media/foo.jpg.

2) Create the per-environment folder — this is the gotcha in Grav 2.0. The environment stream only registers if the directory already exists on disk (a guard added in 2.0 to stop stray hostnames from auto-creating user/env/ dirs — see Setup.php lines \~262-274). So you must make it yourself:

TXT
user/env/mysite.com/media/

where mysite.com is the exact HTTP host. If it's not there, environment:// silently resolves to nothing and you'll only ever hit user://media.

last edited 06/30/26 by Andy Miller

Suggested topics

Topic Participants Replies Views Activity
Support · by BenLaKnet, 5 hours ago
2 31 4 hours ago
Support · by Justin Young, 1 day ago
5 69 17 hours ago
Support · by Justin Young, 1 day ago
3 67 1 day ago
Support · by Anna, 5 days ago
4 107 4 days ago
Support · by Water Science, 4 weeks ago
12 384 5 days ago