2017-12-02 10 views
-1

CRUD가 업로드 한 파일의 이름 대신 데이터베이스에 이미지 바이너리를 저장하려고하는 이유를 알 수 없습니다.Laravel Backpack 이미지 필드 오류 : 1406 데이터가 너무 길어서

모델

public function setImageAttribute($value) 
{ 
    $attribute_name = "image_wheel"; 
    $disk = "wheel"; 
    $destination_path = "wheel_png"; 

    // if the image was erased 
    if ($value==null) { 
     // delete the image from disk 
     \Storage::disk($disk_wheel)->delete($this->{$image_wheel}); 
     \Storage::disk($disk_vehicle)->delete($this->{$image_vehicle}); 

     // set null in the database column 
     $this->attributes[$image_wheel] = null; 
     $this->attributes[$image_vehicle] = null; 
    } 

    // if a base64 was sent, store it in the db 
    if (starts_with($value, 'data:image')) 
    { 
     // 0. Make the image 
     $image = \Image::make($value); 
     // 1. Generate a filename. 
     $filename = md5($value.time()).'.jpg'; 
     // 2. Store the image on disk. 
     \Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream()); 
     // 3. Save the path to the database 
     $this->attributes[$attribute_name] = $destination_path.'/'.$filename; 
    } 
} 

오류 메시지

Next Illuminate\Database\QueryException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'image_wheel' at row 1 (SQL: insert into wheels (name , part_no , alias , series_id , sizes , image_wheel , image_vehicle , description , order , status , featured , -wheel_image_id , -wheel_tags , updated_at , created_at) values (, , , , , data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/ ...........

+0

열의 데이터 유형을 변경해야합니다. – Arafath

+0

이'image_wheel' 필드의 정의는 무엇입니까 – lagbox

+0

@Arafath \t 이미지의 바이너리 대신 md5 ($ value.time()) .jpg라는 이름을 저장하면 안됩니까? – cvassios

답변

0

당신의 image_wheeltext에 변경해야합니다. 아마도 해당 필드의 현재 데이터 형식의 최대 길이에 도달했습니다.

+0

이미지의 바이너리 대신'md5 ($ value.time()) .jpg '라는 이름을 저장하면 안되나요? – cvassios