Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize heavy media file transport in getAssetAction #1244

Open
NonSparkly opened this issue Oct 10, 2023 · 1 comment
Open

Optimize heavy media file transport in getAssetAction #1244

NonSparkly opened this issue Oct 10, 2023 · 1 comment

Comments

@NonSparkly
Copy link

Hi!

We've noticed that the resource return for media assets always contain the media asset itself as a base64 encoded string. This seems to slow down the return by a huge amount and since the URL to the hosted version of the file is also returned, it's unnecessary for a lot of use-cases. Could this be taken out, moved into a parameterized version of the same response or even moved into its own route entirely?

  public function getAssetsAction(string $mediaId, string $extension): SingleResourceResponseInterface {
    $fileProvider = $this->fileProvider;
    $file = $fileProvider->getFile(ArticleMedia::handleMediaId($mediaId), $extension);

    if (null === $file) {
      throw new NotFoundHttpException('Media don\'t exist in storage');
    }

    $mediaManager = $this->mediaManager;

    return new SingleResourceResponse([
        'media_id' => $mediaId,
        'URL' => $mediaManager->getMediaPublicUrl($file),
        //  'media' => base64_encode($mediaManager->getFile($file)), <----- THIS LINE IS HEAVY
        'mime_type' => Mime::getMimeFromExtension($file->getFileExtension()),
        'filemeta' => [],
    ]);
  }
@antonborgstrom
Copy link

I agree!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants