fastadmin接口输出图片 自动拼接网站URL

先自定义常量

复制代码
1.文件接口路径 修改核心文件  application\common\controller\Api.php
    /**
     * 构造方法
     * @access public
     * @param Request $request Request 对象
     */
    public function __construct(Request $request = null)
    {
        $this->request = is_null($request) ? Request::instance() : $request;

        // 控制器初始化
        $this->_initialize();
       //<--代码位置 -->
        if (!defined('IMG_PRE')) {
            define("IMG_PRE", $this->request->domain());//定义获取域名常量
//            define("IMG_PRE", 'https://yunlingshidai.oss-cn-shanghai.aliyuncs.com');//也可以是云端域名
        }
        //<--代码位置 -->
        // 前置操作方法
        if ($this->beforeActionList) {
            foreach ($this->beforeActionList as $method => $options) {
                is_numeric($method) ?
                    $this->beforeAction($options) :
                    $this->beforeAction($method, $options);
            }
        }
    }

ffastadmin 接口输出图片

复制代码
    //修改器
    public function getImageAttr($value)
    {
        if(empty($value)){
            return '';
        }
        $domain=defined("IMG_PRE")?IMG_PRE:'';
        $preg = "/^http(s)?:\\/\\/.+/";
        if(preg_match($preg,$value))
        {
            $data=$value;
        }else{
            $data=$domain.$value;
        }
        return $data;
    }
相关推荐
爱写代码的倒霉蛋17 小时前
FastAPI的接口实现流程讲解
fastapi
在世修行2 天前
干货:文件上传端点解析
python·fastapi·接收上传
云和数据.ChenGuang2 天前
JAVAEE AI工程师路线图
java·人工智能·java-ee·fastapi·springai·langchain4j
风早爽太2 天前
Python 学习笔记:SQLModel 使用外键关联查询数据
python·fastapi·sqlmodel
风早爽太3 天前
Python 学习笔记:数据库迁移工具 ‌Alembic
数据库·python·fastapi·alembic
Web3&Basketball3 天前
用FastAPI+Redis 复刻常驻Agent
redis·bootstrap·fastapi
风早爽太6 天前
Python 开发笔记:配置生产环境中 Celery Worker 的独立进程启动方式
python·fastapi
Java的搬运工8 天前
【无标题】
python·机器学习·docker·fastapi·模型部署·mlops·ai工程化
云和数据.ChenGuang8 天前
langchain4j的RAG入门
人工智能·深度学习·机器学习·语言模型·fastapi
风早爽太8 天前
用 ‌Render‌ 快速部署网站和常见问题解决
python·fastapi