Skip to content

Temporary URL generation support #75

@rvanlaak

Description

@rvanlaak

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 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions