@ekhlas Thanks, but this concept is for the normal file, $request->file(), in this case,I use base64 string.
Apr 11, 2018
15
Level 2
create image from base64 string laravel
Hi I'm writing an API To Upload Image form Android Phone trying to convert the base64 string to image and store in public path storage. now the problem is that: the file is stored but can't open error: image not loaded, try to open it externally to fix formate problem
this is my code for the controller
//get the base-64 from data
$base64_str = substr($arc->document3, strpos($arc->document3, ",")+1);
//decode base64 string
$image = base64_decode($base64_str);
$safeName = str_random(10).'.'.'png';
Storage::disk('public')->put('eejaz/'.$safeName, $image);
Level 2
finally, I get the solution.
$image = $request->image; // your base64 encoded
$image = str_replace('data:image/png;base64,', '', $image);
$image = str_replace(' ', '+', $image);
$imageName = str_random(10).'.'.'png';
\File::put(storage_path(). '/' . $imageName, base64_decode($image));
This the Code for covert any Base64 String to Image and store theme in a local path with file name.
23 likes
Please or to participate in this conversation.