簡體   English   中英

pdf的BinaryContent為null

[英]BinaryContent for a pdf is null

我正在使用Sonata Media Bundle讓用戶上傳PDF文件。 我想使用Imagick創建pdf文檔的預覽圖像。 我有一個$media對象,其中保存有關pdf的信息。

當我die(dump($media)) ,我看到一個包含以下行的媒體對象:

#providerReference: "3c4460aae99b0084d08252065bf3eea1817842d9.pdf"

...並通過以下方式打開該文件:

open -a Preview ./data/storage/faq/0001/01/3c4460aae99b0084d08252065bf3eea1817842d9.pdf

...在我的Mac上產生了完全清晰的PDF。

問題是我還在瀏覽器中看到以下行:

#binaryContent: null

...這意味着我無法將Imagick操縱二進制內容轉儲到臨時文件中。

如何獲得可以交給Imagick的文件路徑?

為了使我獲得對文件的有用引用以及有效的二進制內容,大致上這是可行的。

public function preUpdate(Document $document)
{
    $media = $document->getMedia();
    if ($media === null) {
        return;
    }
    $mediaName = $media->getName();
    if ($media->getContentType() !== 'application/pdf') {
        return;
    }

    $context = $media->getContext();
    $formats = $pool->getFormatNamesByContext($context);

    if (null === $formats) {
        return;
    }

    $provider = $this->getProvider($media->getProviderName());
    $publicUrls = [];

    $fullFilePath = $provider->getReferenceImage($media);



}

...

private function getPool()
{
    return $this->container->get('sonata.media.pool');
}

...

private function getProvider($name)
{
    return $this->container->get($name);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM