阿里云 OSS 文件上传 Driver is not supported 解决方案

开发文件上传功能,使用阿里云OSS服务,config/app.php filesystems.php均已配置,调试出现Driver is not supported,经过一番研究,最终找到问题。

使用流程参考:github.com/apollopy/flysystem-aliy...

阿里云 OSS 文件上传报错 Driver is not supported

出现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();
    }
}
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 3

有加载扩展进来吗?用JohnLui\AliyunOSS\AliyunOSS这个扩展包,文件上传大概如下, public function Oss($file) { $oss = AliyunOSS::boot(config('oss.host'), config('oss.access_id'), config('oss.access_secret')); $oss->setBucket(config('oss.bucket')); if($oss->uploadFile('tmp'.$file, public_path($file))){ return config('oss.domain').'/tmp'.$file; } return null; } oss中配置一下一些基本信息,这样使用起来没啥问题

3年前 评论

文件先下载到本地,再同步到oss上

3年前 评论
PHPer技术栈 (楼主) 3年前
PHPer技术栈 (楼主) 3年前

:heart:fdsfdsf file6851591600185_.pic.jpg

3年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!