简体   繁体   English

Laravel:如何使用 laravel 将 blob 图像保存到存储中

[英]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 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.它只是意味着您想要获取远程图像文件的内容并将其保存在 Laravel 应用程序的存储文件夹中。 You can use file_get_contents for that.您可以为此使用file_get_contents

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: Controller function 或您可能想要使用它的任何地方的代码:

$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参考: https://laracasts.com/discuss/channels/laravel/storing-image-file-retrieved-from-external-url?page=1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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