monstajamss
1 week ago
105
6
Laravel

Image not saving in Database in Laravel

Posted 1 week ago by monstajamss

I am trying to store image into database after it has been converted to base64 and also decoded. The image stores inside the Storage path but does not save into mysql database. What am i doing wrong?

public function updateProfileImage(Request $request)
    {
        $user = auth('api')->user();

        $image = $request->input('image'); // image base64 encoded
        preg_match("/data:image\/(.*?);/",$image,$image_extension); // extract the image extension
        $image = preg_replace('/data:image\/(.*?);base64,/','',$image); // remove the type part
        $image = str_replace(' ', '+', $image);
        $imageName = 'profile' . time() . '.' . $image_extension[1]; //generating unique file name;
        Storage::disk('public')->put($imageName,base64_decode($image));        
        $user->update($request->all());

}

Please sign in or create an account to participate in this conversation.