阿里云 OSS 文件上传 Driver is not supported 解决方案
开发文件上传功能,使用阿里云 OSS 服务,config/app.php filesystems.php 均已配置,调试出现 Driver is not supported,经过一番研究,最终找到问题。
使用流程参考:github.com/apollopy/flysystem-aliy...
出现Driver is not supported,开始检查,发现项目中larave-admin扩展包,初步怀疑是config/admin.php disk配置项与config/filesystems.php不一致导致Driver is not supported错误,于是将admin.php disk 配置与filesystems.php保持一致,执行 php artisan config:clear 清楚缓存命令,然后重新调试,oss文件上传成功,文件路径正常访问,至此问题解决。
namespace App\Http\Controllers\Admin\Common;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class UploadFileController
{
public function uploadFile(Request $request)
{
$file = $request->file('file');
$size = $file->getSize();
$extend = $file->getClientOriginalExtension();
$path = $file->getRealPath();
$name = sprintf('%s.%s', 123, $extend);
Storage::disk('oss')->put($name, file_get_contents($path));
return $file->getClientOriginalName();
}
}
推荐文章: