我正在尝试检索保存为blob的图像,但是当我尝试使用Laravel 5.4将其作为JSON返回时,我一直收到这个错误消息“错误的UTF-8字符,可能不正确编码”。哪里出了问题,我该如何修复它?
database.php mysql配置
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',检索图像
public function getpic()
{
$pic = DB::connection('mysql')
->table('itempictures')
->select('picture')
->get();
return response()->json($pic);
}表的collation为latin1_swedish_ci

列本身的collation为null

镜像的print_r

var_dump of the image

镜像的dd

发布于 2019-09-10 19:43:42
您正在尝试对二进制文件进行json解码,而不是使用原始图像二进制数据进行响应,并使用某种图像类型修改响应内容头部,例如:
public function getImage($id)
{
if($ehtufile = EhtuFile::find($id))
{
return response($ehtufile->filedata, 200)->header('Content-Type', 'image/jpeg');
} else
{
// TODO: No image found:...
$arRes = ['res' => 'Error', 'text' => 'Slide Show Image not found'];
return "nope";
}
}我希望这能有所帮助!
大卫·莱昂斯
https://stackoverflow.com/questions/44724386
复制相似问题