I copied verbatim some sample code which I now I can't find. Anyway here's part of my CustomerController.php
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
`$photo = $customer['photo'];
// convert base64 and save to folder
$image_data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $photo));
//grab a new tmp file
$tmpFilePath=sys_get_temp_dir().'/'.uniqid();
//write the image to it
file_put_contents($tmpFilePath, $image_data);
//move it.
//give it a name
$mime_type = 'jpg';
$imageName = time().'.'.str_replace("image/","",$mime_type);
//or if using File facade
File::move($tmpFilePath, public_path("sq1/$imageName"));
Using postman to test, it returns success, creates the jpg but doesn't display the image.
https://wv-mr.overair.ca/sq1/1543215074.jpg
I used this encoder (I wanted to spare you from attaching the entire base64): https://www.browserling.com/tools/image-to-base64
If it helps what I found is that the actual image is 7,583 bytes, but the decoded image is only 7,483 bytes. Not sure why 100 bytes were lost during decoding.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire