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

How to define environment://media ?

admin media

Solved by Andy Miller View solution

Started by Slebeig 4 weeks ago · 3 replies · 254 views
4 weeks 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 ;) ?

3 weeks ago Solution

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
3 weeks ago

Works, but than in admin backend the images are broken as the path in admin is still user/media even the file is uploaded to the correct position,

last edited 06/30/26 by Slebeig
3 weeks ago

Tested again with Grav 2.0.5 & Admin 2.0.10, still broken links if media is uploaded to environment://media

image.png

Not sure how it is on frontend, as i also have some issues with markdown parsing.

Suggested topics

Topic Participants Replies Views Activity
Support · by TomW, 1 hour ago
1 6 1 hour ago
Support · by Anna, 3 days ago
7 89 4 hours ago
Support · by Anna, 3 days ago
5 96 4 hours ago
Support · by Anna, 4 hours ago
0 8 4 hours ago
Support · by stuart young, 2 days ago
2 65 2 days ago