干预\图像\异常\ NotReadableException无法从给定的二进制数据初始化

时间:2019-01-08 10:16:20

标签: laravel image api postman

我需要使用Blob数据制作图像。我使用Laravel框架和Postman。但是在某些情况下,图像未创建,并且显示错误无法从给定的二进制数据初始化。 我的控制器功能具有以下代码

if ($request->get('logo')) {
        $image = $request->get('logo');
        $pos  = strpos($image, ';');
        $type = explode(':', substr($request->get('logo'), 0, $pos))[1];
        $type = explode("/", $type);
        $name1 = $request->user_id."-".time().'.'.$type[1];
        $profile->logo = $name1;
        if (!File::exists(public_path().'uploads/profiles/logo')) {
            File::makeDirectory(public_path().'uploads/profiles/logo', $mode = 0755, true, true);
        }
        \Image::make($request->get('logo'))->save(public_path('uploads/profiles/logo/').$name1);
    }

$ request-> get('logo')包含值

data:image/jpeg;base64,/9j/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCAQ4B4ADASIAAhEBAxEB/8QAHQAAAQUBAQEBAAAAAAAAAAAAAgADBAUGBwgJAf/EAFwQAAEDAgMGAgYGBwQGBwYBDQIAAwQFEgYiMgcTFEJSYiNyCBUkM4KSFkNTorLCASU0RGNz0jFUYeIJERdkg5MYJjVBRXTwITZRVZSjJ4Sz8hlGVpHTN3GBw+P/xAAbAQADAQEBAQEAAAAAAAAAAAAAAgMEBQEGB//EADoRAAICAQMDAwMCBAUDBAMBAAACAxIEEyIyAQVCERRSIzEzIWIVJEFDNFFhcXIGU5GBg…4V6aSSVCokkkkgCSSSQACkQ43Eu28nMkkvGPFNHGjXhaI5E1UntyO4a+JJJTNLcSpUiNDvzO6Ekl6wik6ywMqAwSSUywCGTJajDcRJJJRGKGZMdk9gKKkkmM4CSSSCQ09/Yo6SSVgO9ejlSrKNU5xD+0Pi0J+X/9NcfxzP8AWWMq3JIr7pRAPlHKkksac2OnP/hkKUEQAkkrHMHgBKy/KkkgBGFmVd49EKNfjqoO/wC6iH30klGf8RfH/Kp2raFMvxbLzaBEPuLyPtCn8Tj+sO3ZAfs+XIkkuBDzNWfxUVNZvdu5FuMKgNjubP0JJLl9yOTHxNQczcjkWCxVWHZLpscgkkkubiCSmfZTqSS7JIkciSSSiRDSSSQA6CaeeSSXi9AIhmkkktgDV5XJXpJJwAvSvSSQBHM86jvGkkqnig3oC0JJIKAJJJLQAlYU0yszaEklOTiBON6wkt8kkuf6dBAr0KSS9AA01MesaSSVlArzkkepMpJLaAkKSSAP/9k=

在通过邮递员API发布数据时,出现了错误

Intervention \ Image \ Exception \ NotReadableException
Unable to init from given binary data.

1 个答案:

答案 0 :(得分:0)

您应该尝试以下操作:

 if ($request->hasFile('logo')) {
        $image = $request->file('logo');
        $pos  = strpos($image, ';');
        $type = explode(':', substr($request->get('logo'), 0, $pos))[1];
        $type = explode("/", $type);
        $name1 = $request->user_id."-".time().'.'.$type[1];
        $profile->logo = $name1;
        if (!File::exists(public_path().'uploads/profiles/logo')) {
            File::makeDirectory(public_path().'uploads/profiles/logo', $mode = 0755, true, true);
        }
        \Image::make($request->get('logo'))->save(public_path('uploads/profiles/logo/').$name1);
    }