jolicode / jolicode/MediaBundle

Temporary URL generation support

Open
#75 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
118
Forks
13
Avg merge
22h 54m
Merged PRs (30d)
3

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:

```php
/* @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 `getUrl` on 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.path` to `/` does let both write + read work correctly, but does also lead to exceptions on some of the API Platform endpoints.
* Flysystem's `FilesystemReader` interface will natively get the `temporaryUrl` method in 4.0.
* Configuring Flysystem's `options.prefix` would allow adding a path prefix, but that would lead to having to configure a different storage for each MediaBundle library.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.