我正在尝试检索保存为blob的图像,但我一直收到此错误"格式错误的UTF-8字符,可能编码错误"当我尝试使用Laravel 5.4将其作为JSON返回时。有什么问题,我该如何解决?
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
答案 0 :(得分:0)
您正尝试对二进制文件进行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";
}
}
我希望这会有所帮助!,
David Lyons