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;
    }
相关推荐
yaoty19 小时前
Python日志存储:从单机同步到分布式异步的7种方案
fastapi·日志·logger
星空椰21 小时前
FastAPI 进阶:中间件、依赖注入与 ORM
python·fastapi
码界筑梦坊21 小时前
220-基于Python的诺贝尔奖数据可视化分析系统
开发语言·python·信息可视化·数据分析·毕业设计·fastapi
钱彬 (Qian Bin)1 天前
FastAPI的Alembic踩坑记录:缺失历史迁移脚本如何保留数据重建版本控制
sqlite·fastapi·数据库迁移·alembic
wanderist.1 天前
从 TCP 到 JSON:一次 FastAPI + LLM 生产环境 “Unexpected end of JSON input” 的底层剖析
tcp/ip·json·fastapi
SmartBrain2 天前
技术洞察:SpringAI与LangGraph选型对比
人工智能·spring boot·架构·langchain·aigc·fastapi
那个松鼠很眼熟w2 天前
python fastapi 快速创建web应用
python·fastapi
SmartBrain3 天前
FastAPI实战(第三部分):浏览历史的接口开发详解
数据库·人工智能·aigc·fastapi
布局呆星3 天前
Python 入门:FastAPI + SQLite3 + Requests 基础教学
python·sqlite·fastapi
忘忧记3 天前
pythonQT版本的图书管理系统
python·fastapi