Php 从GuzzleHttp、getContents的乱码数据写入文件(GuzzleHttp\Psr7\Response)
我一直在尝试的是从数据中获取一个文件,它应该是可读的 下面是一行使用GoogleDriveAPI的代码Php 从GuzzleHttp、getContents的乱码数据写入文件(GuzzleHttp\Psr7\Response),php,guzzle,Php,Guzzle,我一直在尝试的是从数据中获取一个文件,它应该是可读的 下面是一行使用GoogleDriveAPI的代码 $result = $this->service->files->export("ID", 'mimeType', array( 'alt' => 'media')) ->getBody() ->getContents(); $result获取GuzzleHttp\Psr7\Response的对象。这
$result = $this->service->files->export("ID", 'mimeType', array(
'alt' => 'media'))
->getBody()
->getContents();
$result
获取GuzzleHttp\Psr7\Response
的对象。这最初是一个可读的Google.doc
文件。但是,$result
是乱码,我用var\u dump()
确认了它
有没有人想到将GuzzleHttp\Psr7\Response
对象转换(或还原)为可读文件?
另外,如果您能给出将恢复的$result
保存为doc、pdf或任何其他主要格式的想法,我将不胜感激
仅供参考:我使用的是Laravel 5,它具有GuzzleHttp。您需要用read()替换getContents 这对我很有用:
$file = $service->files->export($request->id, 'application/pdf', array('alt' => 'media' ));
$size = $file->getBody()->getSize();
$content = $file->getBody()->read($size);