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;
    }
相关推荐
安冬的码畜日常27 分钟前
【玩转 Postman 接口测试与开发2_020】(完结篇)DIY 实战:随书示例 API 项目本地部署保姆级搭建教程(含完整调试过程)
python·测试工具·django·接口测试·postman·fastapi·api项目
曲幽1 天前
FastAPI快速上手:请求与响应的核心玩法
python·fastapi·web·form·get·post
祁思妙想2 天前
Python中的FastAPI框架的设计特点和性能优势
开发语言·python·fastapi
Swizard2 天前
告别“意大利面条”:FastAPI 生产级架构的最佳实践指南
python·fastapi
曲幽2 天前
FastAPI入门:从简介到实战,对比Flask帮你选对框架
python·flask·fastapi·web·route·uv·uvicorn·docs
龙腾AI白云2 天前
基于Tensorflow库的RNN模型预测实战Tensorflow库简介循环神经网络简介
人工智能·fastapi
写文章的大米3 天前
10分钟用Python搭个接口,还能自动生成文档?
python·fastapi
weixin_462446234 天前
【实践原创】使用 FastAPI 实现 Coze 流式聊天 SSE 接口
fastapi·扣子mcp
吴佳浩 Alben4 天前
Python入门指南(五) - 为什么选择 FastAPI?
开发语言·python·fastapi
kkoral4 天前
基于MS-Swift 为 Qwen3-0.6B-Base 模型搭建可直接调用的 API 服务
python·conda·fastapi·swift