-
Notifications
You must be signed in to change notification settings - Fork 7
Description
In our API Platform project we're integrating a S3 compatible bucket as it's filesystem (MinIO in local dev env). One of the goals is to serve the asserts from the bucket directly through the use of temporary URLs, to reduce memory consumption on the application server.
Temporary URLs are not fully supported by the bundle yet. The filesystem is available through the library, so the following call would be successful when the correct $path would be available:
/* @var JoliCode\MediaBundle\Library\LibraryContainer $libraryContainer */
$libraryContainer->getDefault()->getOriginalStorage()->getFilesystem()->temporaryUrl($path, $expiresAt);Actual result
When a library's url_generator.path config section is set, the write and read paths do not match anymore, resulting in incorrect temporary urls.
On write, the resource which is persisted within a doctrine entity doesn't get prepended that route path. On read; when retrieving the path through StorableInterface::getUrl during normalization, the configured path does get prepended.
- write:
/path/to/resource.png - read through
getUrlon a custom normalizer:/media/original/path/to/resource.png
Result; the path doesn't exist on the bucket, so the resource can't get resolved.
Expected result
Having the prefix on write would feel most natural, also because it clearly organizes the resources on the bucket according to their library configuration.
In what way would it be easiest to support the generation of temporary urls? What about 1) prepending the resource to the path on write as well, and 2) as result of that actually rename the url_generator configuration to something more generic like `
Additional context
- Configuring
url_generator.pathto/does let both write + read work correctly, but does also lead to exceptions on some of the API Platform endpoints. - Flysystem's
FilesystemReaderinterface will natively get thetemporaryUrlmethod in 4.0. - Configuring Flysystem's
options.prefixwould allow adding a path prefix, but that would lead to having to configure a different storage for each MediaBundle library.