首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel干预-无法从给定的二进制数据中插入

Laravel干预-无法从给定的二进制数据中插入
EN

Stack Overflow用户
提问于 2022-06-06 06:59:02
回答 1查看 242关注 0票数 0

我在我的一个项目中使用"intervention/image": "^2.5"。它运行良好,除了代码的一部分,其中我检索一个图像。

我一直得到一个Unable to init from given binary data错误,我不知道为什么。

这个文件是存在的,但我想不出来。

我的代码如下;

代码语言:javascript
复制
$path = '/image-storage/492/1/testimage.jpg';
$file = Storage::get($path);
ob_end_clean();

return Image::make($file)->response();

下面是本地的filesystem.php配置

代码语言:javascript
复制
'local' => [
    'driver' => 'local',
    'root' => storage_path('app'),
],
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-08 21:53:06

Storage::get($path)将文件内容作为字符串返回,该字符串可能无法转换为图像的有效二进制数据::make()以便能够读取。

您可以尝试将图像的路径传递给make方法。

代码语言:javascript
复制
//If testimage.jpg is located at storage/app/image-storage/492/1
$path = storage_path('app/image-storage/492/1/testimage.jpg');

//if testimage.jpg is located at storage/app/public/image-storage/492/1/, then
//$path = storage_path('app/public/image-storage/492/1/testimage.jpg');

return Image::make($path)->response();

或者您可以创建一个新的Illuminate\Http\File实例,然后将其传递给make方法。

代码语言:javascript
复制
//If testimage.jpg is located at storage/app/image-storage/492/1
$path = storage_path('app/image-storage/492/1/testimage.jpg');

//if testimage.jpg is located at storage/app/public/image-storage/492/1/, then
//$path = storage_path('app/public/image-storage/492/1/testimage.jpg');

$file = new \Illuminate\Http\File($path);

Image::make($file)->response();

干预映像接受二进制数据或SplFileInfo实例。Illuminate\Http\File扩展了Symfony\Component\HttpFoundation\File\File,后者扩展了\SplFileInfo

干预图像-读取图像

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72514083

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档