简体   繁体   中英

Laravel: how to save blob image to storage with laravel

i have a image blob url like this: blob: http://127.0.0.1:5500/d97212fe-8f01-4486-8840-36acc57f77bc , how i can store it to storage image with Laravel

It simply means you want to get the contents of a remote image file and save it in your Laravel application's storage folder. You can use file_get_contents for that.

The complete code will be: Import storage Facade on the top of your file:

use Storage;

Code in the Controller function or anywhere you may want to use it:

$url = "http://www.google.co.in/intl/en_com/images/srpr/logo1w.png";
$contents = file_get_contents($url);
$name = time().'.png';
Storage::put($name, $contents);

It's simple dummy code, you will have to add logic to create a filename.

Reference: https://laracasts.com/discuss/channels/laravel/storing-image-file-retrieved-from-external-url?page=1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM