[英]BinaryContent for a pdf is null
I am using Sonata Media Bundle to let users upload PDF files. 我正在使用Sonata Media Bundle让用户上传PDF文件。 I want to use Imagick to create a preview image of a pdf document.
我想使用Imagick创建pdf文档的预览图像。 I have a
$media
object that holds information about my pdf. 我有一个
$media
对象,其中保存有关pdf的信息。
When I do die(dump($media))
, I see a media object that includes the following line: 当我
die(dump($media))
,我看到一个包含以下行的媒体对象:
#providerReference: "3c4460aae99b0084d08252065bf3eea1817842d9.pdf"
... and opening that file via: ...并通过以下方式打开该文件:
open -a Preview ./data/storage/faq/0001/01/3c4460aae99b0084d08252065bf3eea1817842d9.pdf
... on my mac yields a fully legible PDF. ...在我的Mac上产生了完全清晰的PDF。
The problem is that I also see the following line in the browser: 问题是我还在浏览器中看到以下行:
#binaryContent: null
... which means that I can't dump the binary content into a temporary file for the purpose of having Imagick manipulate it. ...这意味着我无法将Imagick操纵二进制内容转储到临时文件中。
How do I get a file path that I can hand off to Imagick? 如何获得可以交给Imagick的文件路径?
Here is roughly what worked in order to get me a useful reference to a file, complete with valid binary content. 为了使我获得对文件的有用引用以及有效的二进制内容,大致上这是可行的。
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.