nbcio-boot项目的文件上传与回显处理方法

更多ruoyi-nbcio功能请看演示系统

gitee源代码地址

前后端代码: https://gitee.com/nbacheng/ruoyi-nbcio

演示地址:RuoYi-Nbcio后台管理系统

更多nbcio-boot功能请看演示系统

gitee源代码地址

后端代码: https://gitee.com/nbacheng/nbcio-boot

前端代码:https://gitee.com/nbacheng/nbcio-vue.git

在线演示(包括H5) : http://122.227.135.243:9888

· 基于jeecgboot的nbcio-boot里面有涉及文件的上传与回显或下载,里面很多模块都有这方面的需求,所以这里统一对这部分做说明。

因为支持本地与OSS的文件上传与处理,所以这里主要进行本地与其它类型的区分

在yml进行设置,如下,主要是类型与上传地址

java 复制代码
jeecg :
  # 是否启用安全模式
  safeMode: false
  # 签名密钥串(前后端要一致,正式发布请自行修改)
  signatureSecret: nbcioestar05f1c54d63749eda95f9fa6d49v442aestarnbcio
  # 本地:local\Minio:minio\阿里云:alioss
  uploadType: local
  path :
    #文件上传根目录 设置
    upload: /opt/upFiles
    #webapp文件路径
    webapp: /opt/webapp

1、后端的处理

所以在java调用的时候需要上面信息,同时调用下面的方法

java 复制代码
@Value(value = "${jeecg.path.upload}")
	private String uploadpath;

	/**
	* 本地:local minio:minio 阿里:alioss
	*/
	@Value(value="${jeecg.uploadType}")
	private String uploadType;
java 复制代码
if(CommonConstant.UPLOAD_TYPE_LOCAL.equals(uploadType)){
                    		uploadPath = CommonUtils.uploadLocal(FileUtil.getMultipartFile(imageFile),"/bs",uploadpath);
                            
                        }else{
                        	uploadPath = CommonUtils.upload(FileUtil.getMultipartFile(imageFile), "/bs", uploadType);
                        }

这样可以返回上传的地址,以便保存到数据库里。

2、前端的处理

前端图片显示的时候需要进行转换,如:src="getImgView(file_url)",

:href="downloadFile(file_url)"

javascript 复制代码
/* 图片预览 */
      getImgView(text){
        if(text && text.indexOf(",")>0){
          text = text.substring(0,text.indexOf(","))
        }
        return getFileAccessHttpUrl(text)
      },
      downloadFile(text){
        if(!text){
          this.$message.warning("未知的文件")
          return;
        }
        if(text.indexOf(",")>0){
          text = text.substring(0,text.indexOf(","))
        }
        let url = getFileAccessHttpUrl(text)
        return url;
      },

或者用下面的下载方式

javascript 复制代码
downloadFile(text){
      if(!text){
        this.$message.warning("未知的文件")
        return;
      }
      if(text.indexOf(",")>0){
        text = text.substring(0,text.indexOf(","))
      }
      let url = getFileAccessHttpUrl(text)
      window.open(url);
    },
相关推荐
虾球xz17 分钟前
游戏引擎学习第126天
java·学习·游戏引擎
郑祎亦33 分钟前
Java 关键字 volatile
java·开发语言·jvm
不会飞的小龙人36 分钟前
Quickwit获取Kafka数据源消息
java·docker·容器·kafka·quickwit
暗月Moon38 分钟前
vue2中,打包报错ERROR in /node_modlules/@types/lodash/common/common.d.ts 26
npm·vue
诗诗的博客1 小时前
jmeter聚合报告如何添加单位_性能测试连载(8)jmeter压力测试中的难点解析
java·开发语言
luoluoal1 小时前
java项目之基于ssm的线上旅游体验系统(源码+文档)
java·mysql·mybatis·ssm·源码
茂茂在长安2 小时前
JAVA面试_进阶部分_23种设计模式总结
java·设计模式·面试
m0_748232922 小时前
Spring Cloud Gateway 整合Spring Security
java·后端·spring
浅念同学3 小时前
JavaWeb-Servlet对象生命周期
java·网络·spring boot·servlet·java-ee·tomcat
Dyan_csdn3 小时前
【Java项目】基于Spring Boot的简历系统
java·数据库·spring boot·spring·tomcat