第一步,先安装阿里云上传插件
第二步,找到阿里云上传插件的【服务器中转上传文件 】的upload方法。
第三步,对比一下,可以看到这么个情况,这个服务器中转的代码跟API接口的代码基本一样的,只是下面多了这段代码
//文件绝对路径
$filePath = $upload->getFile()->getRealPath() ?: $upload->getFile()->getPathname();
try {
$ret = $oss->uploadFile($config['bucket'], ltrim($attachment->url, "/"), $filePath);
//成功不做任何操作
} catch (\Exception $e) {
$attachment->delete();
@unlink($filePath);
$this->error("上传失败");
}```
第四步,你懂的,把服务器中转的阿里云上传部分的代码复制粘贴到api接口的方法里面。搞定。