all(), [ 'tag' => 'required|alpha_dash', ], [ 'tag.required' => 'tag必填', 'tag.alpha_dash' => 'tag只能为字母数字中/下划线', ] ); if ($validator->fails()) { throw new \Exception($validator->messages()->first()); } $result = (new AttachmentServer())->uploadAttachment($request, $request->post('file'), $request->post('tag'), 10 * 1024 * 1024, [ 'image/jpeg', 'image/png', 'image/gif', 'video/mp4', ]); } catch (\Exception $exception) { return $this->error($exception->getMessage()); } return $this->success(['file' => $result], 0, trans("api.UPLOAD_SUCCESS")); } /** * @param Request $request * @return \Illuminate\Http\JsonResponse * parse_url($url); * array ( 'scheme' => 'https', 'host' => 'zhengda.oss-cn-chengdu.aliyuncs.com', 'path' => '/api_avatar/2022-07/14/1271657787068220714.jpeg', ) */ public function delete(Request $request) { $picUrl = $request->pic_url; if(empty($picUrl)){ return $this->error('路径必填!'); } $arr = parse_url($picUrl); $path = substr($arr['path'], 1); $result = (new AttachmentServer())->deleteAttachment($path); if ($result) { return $this->success([]); } else { return $this->error('',ErrorCode::ATTACHMENT_DELETE_FAILED); } } }