File Gate is an Omeka S module that make file download requests go through the application, allowing other modules to do things like access control, analytics, ...
File Gate rewrites the URLs of original files. For instance it will rewrite
https://omeka.example.com/files/original/8e595076a83fb5c1e867e468f1558808b2b8d2fb.jpg
to
https://omeka.example.com/s/some-site/filegate/b3JpZ2luYWwvOGU1OTUwNzZhODNmYjVjMWU4NjdlNDY4ZjE1NTg4MDhiMmI4ZDJmYi5qcGc
When a request is made to that URL, it will trigger an event, which other modules can attach listeners to.
Listeners may return a Laminas\Http\Response
object. In that case, this
response will be sent immediately and the remaining listeners will not be
executed.
If no listeners return a response, the default response is sent, which is a 302
redirect to the real file URI.
For instance:
<?php
public function attachListeners(SharedEventManagerInterface $sharedEventManager)
{
$sharedEventManager->attach('*', 'filegate', [$this, 'onFileAccess']);
}
public function onFileAccess ($event)
{
$controller = $event->getTarget();
$storagePath = $event->getParam('storagePath');
// Get real URI
$fileStore = $this->getServiceLocator()->get('Omeka\File\Store');
$uri = $fileStore->getUri($storagePath);
// Get HTTP request
$request = $controller->getRequest();
// Optionally return a Response
$response = new \Laminas\Http\Response;
$response->setStatusCode(403);
return $response;
}
- Omeka S 4.0.0 or greater
- File URL rewrite happens only while browsing sites. On the admin interface there is no URL rewrite.
- File URL rewrite happens only for original files. Thumbnails, assets, and other files URLs are not rewritten.
- It is compatible with the following file stores:
- The
Local
file store (the default) - All AnyCloud file stores
- The
This module is distributed under the GNU General Public License, version 3 (GPLv3).
The full text of this license is given in the LICENSE
file.