Fajar's avatar
Level 2

something wrong

hi i want to ask

I have 2 applications with image uploads contained in 2 applications

in the first application the image update was successful but in the second application an error appeared

Unable to init from given binary data.

update function

public function update(Request $request, Produk $produck)
    {
        $this->validate($request, [
            'kategori_id'   => 'required',
            'name'          => 'required',
            'harga'         => 'required',
            'stok'          => 'required',
            'desk'          => 'required',
        ]);

        $this->storeImage($produck);

        return redirect()->back();
    }

storeImage

private function storeImage($produck){
        if(request()->has('image')){
            $produck->update([
                'image'  => request()->image->store('uploads','public'),
            ]);

            $image = Image::make(public_path('storage/'. $produck->image))->fit(300,300, null, 'top-left');
            $image->save();
        }
    }

thx

0 likes
3 replies
Sinnbeck's avatar

What line throws that error? The error message should be longer than just "Unable to init from given binary data."

Fajar's avatar
Level 2

@Sinnbeck

throw new NotReadableException(
                "Unable to init from given binary data."
            );
Nakov's avatar

Try this:

$image = Image::make(public_path('storage/'. base64_decode($produck->image)))->fit(300,300, null, 'top-left');

Please or to participate in this conversation.