• notice
  • Congratulations on the launch of the Sought Tech site

laravel - way to store base64 images

installation kit

composer require melihovv/base64-image-decoder

Usage example

After decoding the package, you can customize the file name and use Storage::put to save the image file under storage\app.

use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Melihovv\Base64ImageDecoder\Base64ImageDecoder;
 
try {
    $dataUri = 'data:image/gif;base64,R0lGODlhLAH6AOZ/AMyokXJMK0uE...';
    $decoder = new Base64ImageDecoder($dataUri, ['jpeg', 'jpg', 'png', 'gif']);
    $fileName = strtoupper(Str::uuid()) . "." . $decoder->getFormat();
    Storage::put($fileName, $decoder->getDecodedContent());
}
catch (\Exception $e) {
    dd($e->getMessage());
}


Tags

Technical otaku

Sought technology together

Related Topic

0 Comments

Leave a Reply

+