如何在Laravel 5.5中的S3存储桶中上传base64图像

use*_*778 2 php base64 file-upload amazon-s3 laravel

我正在使用laravel api应用程序,我必须将base64编码的图像上传到AWS S3存储桶。

我可以直接上传图片

$this->request->imageInput->store('public');//in local server
Storage::disk('s3')->put('FILENAME', file_get_contents('imageInput'));//in S3 server
Run Code Online (Sandbox Code Playgroud)

如何将base64编码的图像上传到AWS S3存储桶,并在获得图像信息的地方获得响应?

Azo*_*ole 6

list($baseType, $image) = explode(';', $base64);
list(, $image) = explode(',', $image);
$image = base64_decode($image);

$imageName = rand(111111111, 999999999) . '.png';
$p = Storage::disk('s3')->put('filepath/' . $imageName, $image, 'public'); // old : $file
Run Code Online (Sandbox Code Playgroud)

关键是您需要专门指定文件名。

适配器无法获取base64数据的真实路径。我猜是因为base64数据不是文件对象。