图像blob格式错误的UTF-8字符,可能编码错误

时间:2017-06-23 14:53:20

标签: php laravel encoding utf-8

我正在尝试检索保存为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);
}

表格collationlatin1_swedish_ci

enter image description here

列本身的collationnull

enter image description here

print_r图片 enter image description here

var_dump of the image enter image description here

dd图片 enter image description here

1 个答案:

答案 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

相关问题