Skip to content

Optimize heavy media file transport in getAssetAction #1244

@NonSparkly

Description

@NonSparkly

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' => [],
    ]);
  }

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