我想从Laravel资源控制器返回图像流show()
方法,这可能吗?
我正在尝试使用 aws-sdk S3 流包装器,它通过流提供图像数据,以避免将整个图像加载到内存中,并从show()
方法返回该图像。
适用于 PHP 的 AWS S3 流包装器的文档:https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/s3-stream-wrapper.html
您可以使用streamDownload
返回。
您必须使用所需的代码填写函数才能打开和回显远程数据。根据需要替换内容类型标头和文件名。
return response()->streamDownload(function() {
// stream contents here
// s3 fetch, echo file contents from remote url, etc.
}, "super-duper.png", ['content-type' => 'image/png']);