1、web分布式文件系统文件下载路径生成逻辑不正确,进行修改
| | |
| | | public String fileSysRestUrl; //文件名称的哈希值对应的文件系统的restful URL,在配置文件中配置 |
| | | public String fileWebPath; //文件名称的哈希值对应的文件系统的显示及下载文件的web path,动态生成 |
| | | public String fileWebUrl; //文件名称的哈希值对应的文件系统的显示文件的web URL,在配置文件中配置 |
| | | public String fileWebDownloadUrl; //文件名称的哈希值对应的文件系统的Action下载文件的web URL,在配置文件中配置 |
| | | public String fileWebDownloadPath; //下载文档的Controller的相对路径 |
| | | |
| | | public String toString(){ |
| | | return "fileName=" + fileName + "\n" |
| | |
| | | + "fileSysRestUrl=" + fileSysRestUrl + "\n" |
| | | + "fileWebPath=" + fileWebPath + "\n" |
| | | + "fileWebUrl=" + fileWebUrl + "\n" |
| | | + "fileWebDownloadUrl=" + fileWebDownloadUrl; |
| | | + "fileWebDownloadPath=" + fileWebDownloadPath; |
| | | } |
| | | |
| | | /** |
| | |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * web文件上传示例 |
| | | */ |
| | |
| | | @Value("${dy.webFile.fmUrl}") |
| | | private String fmUrl ; |
| | | |
| | | /** |
| | | * 上传照片图片文件 (当前只对png jpg格式图片支持缩略图) |
| | | * @param file |
| | | * @return |
| | | */ |
| | | @PostMapping("/upPhoto") |
| | | @SsoPowerAop(power = "-1") //登录与权限同时验证 |
| | | //https://blog.zhengru.top/posts/33486.html#%E5%8D%95%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0 |
| | |
| | | fileNameGrp[1], |
| | | null); |
| | | String fileMainName = fileOp.getFileMainName(frVo.fileName) ; |
| | | Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath, frVo.fileWebDownloadUrl); |
| | | FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1], (frVo.getFileWebUrl() + frVo.getFileWebPath()), fileOp.getImgFileZipPath(frVo.getFileWebUrl() + frVo.getFileWebPath()), frVo.fileWebDownloadUrl) ; |
| | | Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath); |
| | | FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1], (frVo.getFileWebUrl() + frVo.getFileWebPath()), fileOp.getImgFileZipPath(frVo.getFileWebUrl() + frVo.getFileWebPath()), frVo.fileSysRestUrl + frVo.fileWebDownloadPath + id) ; |
| | | return BaseResponseUtils.buildSuccess(fvo) ; |
| | | }else { |
| | | return BaseResponseUtils.buildError("未得到上传文件的扩展名"); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 上传录音音频文件 |
| | | * @param file |
| | | * @return |
| | | */ |
| | | @PostMapping("/upPhone") |
| | | @SsoPowerAop(power = "-1") |
| | | public BaseResponse<?> upPhone(MultipartFile file) { |
| | |
| | | fileNameGrp[1], |
| | | null); |
| | | String fileMainName = fileOp.getFileMainName(frVo.fileName) ; |
| | | Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath, frVo.fileWebDownloadUrl); |
| | | FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null, frVo.fileWebDownloadUrl) ; |
| | | Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath); |
| | | FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null, frVo.fileSysRestUrl + frVo.fileWebDownloadPath + id) ; |
| | | return BaseResponseUtils.buildSuccess(fvo) ; |
| | | }else { |
| | | return BaseResponseUtils.buildError("未得到上传文件的扩展名"); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 上传录像视频文件 |
| | | * @param file |
| | | * @return |
| | | */ |
| | | @PostMapping("/upVideo") |
| | | @SsoPowerAop(power = "-1") |
| | | public BaseResponse<?> upVideo(MultipartFile file) { |
| | |
| | | fileNameGrp[1], |
| | | null); |
| | | String fileMainName = fileOp.getFileMainName(frVo.fileName) ; |
| | | Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath, frVo.fileWebDownloadUrl); |
| | | FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null, frVo.fileWebDownloadUrl) ; |
| | | Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath); |
| | | FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null, frVo.fileSysRestUrl + frVo.fileWebDownloadPath + id) ; |
| | | return BaseResponseUtils.buildSuccess(fvo) ; |
| | | }else { |
| | | return BaseResponseUtils.buildError("未得到上传文件的扩展名"); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 上传文档文件 |
| | | * @param file |
| | | * @return |
| | | */ |
| | | @PostMapping("/upDocument") |
| | | @SsoPowerAop(power = "-1") |
| | | public BaseResponse<?> upDocument(MultipartFile file) { |
| | |
| | | fileNameGrp[1], |
| | | null); |
| | | String fileMainName = fileOp.getFileMainName(frVo.fileName) ; |
| | | Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath, frVo.fileWebDownloadUrl); |
| | | FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null, frVo.fileWebDownloadUrl) ; |
| | | Long id = this.saveFileInfo(fileNameGrp[0], fileNameGrp[1], fileMainName, frVo.fileNameHash, frVo.fileWebPath); |
| | | FileVo fvo = new FileVo(id, frVo.fileNameHash, fileNameGrp[0], fileNameGrp[1],frVo.getFileWebUrl() + frVo.getFileWebPath(), null, frVo.fileSysRestUrl + frVo.fileWebDownloadPath + id) ; |
| | | return BaseResponseUtils.buildSuccess(fvo) ; |
| | | }else { |
| | | return BaseResponseUtils.buildError("未得到上传文件的扩展名"); |
| | |
| | | * @param filePath 文件服务端存储相对路径 |
| | | * @return |
| | | */ |
| | | private Long saveFileInfo(String orgName, String extName, String newName, Integer hash, String filePath, String downloadPath){ |
| | | private Long saveFileInfo(String orgName, String extName, String newName, Integer hash, String filePath){ |
| | | OthFile po = new OthFile() ; |
| | | po.orgName = orgName ; |
| | | po.extName = extName ; |
| | | po.newName = newName ; |
| | | po.hash = hash ; |
| | | po.filePath = filePath ; |
| | | po.downloadPath = downloadPath ; |
| | | po.dt = new Date() ; |
| | | return this.sv.save(po) ; |
| | | } |
| | | |
| | |
| | | public String filePath; |
| | | |
| | | /** |
| | | * 文件下载路径 |
| | | */ |
| | | public String downloadPath; |
| | | |
| | | /** |
| | | * 文件上载日期 |
| | | */ |
| | | @TableField(value = "dt", fill = FieldFill.INSERT) |
| | |
| | | other: |
| | | webPort: 12348 |
| | | idSuffix: 5 |
| | | |
| | | file: |
| | | idSuffix: 99 |
| | | file1: |
| | |
| | | hashEnd: 5461 |
| | | restUrl: http://127.0.0.1:${pms.file1.webPort}/file #file是上下文 |
| | | webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ #nginx服务路径 |
| | | webDownloadUrl: http://127.0.0.1:${pms.file1.webPort}/file/download/down?id= |
| | | webDownloadPath: /download/down?id= #实际下载webUrl= restUrl + webDownloadPath |
| | | sv2: |
| | | id: dyFile2 |
| | | absolutePath: E:/java/nginx-1.24.0/html/webfiles/ |
| | |
| | | hashEnd: 10923 |
| | | restUrl: http://127.0.0.1:${pms.file2.webPort}/file |
| | | webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ |
| | | webDownloadUrl: http://127.0.0.1:${pms.file2.webPort}/file/download/down?id= |
| | | webDownloadPath: /download/down?id= |
| | | sv3: |
| | | id: dyFile3 |
| | | absolutePath: E:/java/nginx-1.24.0/html/webfiles/ |
| | |
| | | hashEnd: 16385 |
| | | restUrl: http://127.0.0.1:${pms.file3.webPort}/file |
| | | webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ |
| | | webDownloadUrl: http://127.0.0.1:${pms.file3.webPort}/file/download/down?id= |
| | | webDownloadPath: /download/down?id= |
| | | sv4: |
| | | id: dyFile4 |
| | | absolutePath: E:/java/nginx-1.24.0/html/webfiles/ |
| | |
| | | hashEnd: 21847 |
| | | restUrl: http://127.0.0.1:${pms.file4.webPort}/file |
| | | webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ |
| | | webDownloadUrl: http://127.0.0.1:${pms.file4.webPort}/file/download/down?id= |
| | | webDownloadPath: /download/down?id= |
| | | sv5: |
| | | id: dyFile5 |
| | | absolutePath: E:/java/nginx-1.24.0/html/webfiles/ |
| | |
| | | hashEnd: 27309 |
| | | restUrl: http://127.0.0.1:${pms.file5.webPort}/file |
| | | webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ |
| | | webDownloadUrl: http://127.0.0.1:${pms.file5.webPort}/file/download/down?id= |
| | | webDownloadPath: /download/down?id= |
| | | sv6: |
| | | id: dyFile6 |
| | | absolutePath: E:/java/nginx-1.24.0/html/webfiles/ |
| | |
| | | hashEnd: 32767 |
| | | restUrl: http://127.0.0.1:${pms.file6.webPort}/file |
| | | webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ |
| | | webDownloadUrl: http://127.0.0.1:${pms.file6.webPort}/file/download/down?id= |
| | | webDownloadPath: /download/down?id= |
| | | sv7: |
| | | id: dyFile7 |
| | | absolutePath: E:/java/nginx-1.24.0/html/webfiles/ |
| | |
| | | hashEnd: 38229 |
| | | restUrl: http://127.0.0.1:${pms.file7.webPort}/file |
| | | webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ |
| | | webDownloadUrl: http://127.0.0.1:${pms.file7.webPort}/file/download/down?id= |
| | | webDownloadPath: /download/down?id= |
| | | sv8: |
| | | id: dyFile8 |
| | | absolutePath: E:/java/nginx-1.24.0/html/webfiles/ |
| | |
| | | hashEnd: 43691 |
| | | restUrl: http://127.0.0.1:${pms.file8.webPort}/file |
| | | webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ |
| | | webDownloadUrl: http://127.0.0.1:${pms.file8.webPort}/file/download/down?id= |
| | | webDownloadPath: /download/down?id= |
| | | sv9: |
| | | id: dyFile9 |
| | | absolutePath: E:/java/nginx-1.24.0/html/webfiles/ |
| | |
| | | hashEnd: 49153 |
| | | restUrl: http://127.0.0.1:${pms.file9.webPort}/file |
| | | webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ |
| | | webDownloadUrl: http://127.0.0.1:${pms.file9.webPort}/file/download/down?id= |
| | | webDownloadPath: /download/down?id= |
| | | sv10: |
| | | id: dyFile10 |
| | | absolutePath: E:/java/nginx-1.24.0/html/webfiles/ |
| | |
| | | hashEnd: 54615 |
| | | restUrl: http://127.0.0.1:${pms.file10.webPort}/file |
| | | webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ |
| | | webDownloadUrl: http://127.0.0.1:${pms.file10.webPort}/file/download/down?id= |
| | | webDownloadPath: /download/down?id= |
| | | sv11: |
| | | id: dyFile11 |
| | | absolutePath: E:/java/nginx-1.24.0/html/webfiles/ |
| | |
| | | hashEnd: 60077 |
| | | restUrl: http://127.0.0.1:${pms.file11.webPort}/file |
| | | webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ |
| | | webDownloadUrl: http://127.0.0.1:${pms.file11.webPort}/file/download/down?id= |
| | | webDownloadPath: /download/down?id= |
| | | sv12: |
| | | id: dyFile12 |
| | | absolutePath: E:/java/nginx-1.24.0/html/webfiles/ |
| | |
| | | hashEnd: 65535 |
| | | restUrl: http://127.0.0.1:${pms.file12.webPort}/file |
| | | webUrl: http://127.0.0.1:${pms.nginx.webPort}/webfiles/ |
| | | webDownloadUrl: http://127.0.0.1:${pms.file12.webPort}/file/download/down?id= |
| | | webDownloadPath: /download/down?id= |
| | |
| | | <result column="new_name" property="newName" /> |
| | | <result column="hash" property="hash" /> |
| | | <result column="file_path" property="filePath" /> |
| | | <result column="download_path" property="downloadPath" /> |
| | | <result column="dt" property="dt" /> |
| | | </resultMap> |
| | | <sql id="Base_Column_List"> |
| | | <!--@mbg.generated--> |
| | | id, org_name, ext_name, new_name, hash, file_path, download_path, dt |
| | | id, org_name, ext_name, new_name, hash, file_path, dt |
| | | </sql> |
| | | <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap"> |
| | | <!--@mbg.generated--> |
| | |
| | | </delete> |
| | | <insert id="insert" parameterType="com.dy.pmsGlobal.pojoOth.OthFile"> |
| | | <!--@mbg.generated--> |
| | | insert into oth_file (id, org_name, ext_name, new_name, hash, file_path, download_path, |
| | | insert into oth_file (id, org_name, ext_name, new_name, hash, file_path, |
| | | dt) |
| | | values (#{id}, #{orgName}, #{extName}, #{newName}, #{hash}, #{filePath}, #{downloadPath}, |
| | | values (#{id}, #{orgName}, #{extName}, #{newName}, #{hash}, #{filePath}, |
| | | #{dt}) |
| | | </insert> |
| | | <insert id="insertSelective" parameterType="com.dy.pmsGlobal.pojoOth.OthFile"> |
| | |
| | | <if test="filePath != null"> |
| | | file_path, |
| | | </if> |
| | | <if test="downloadPath != null"> |
| | | download_path, |
| | | </if> |
| | | <if test="dt != null"> |
| | | dt, |
| | | </if> |
| | |
| | | </if> |
| | | <if test="filePath != null"> |
| | | #{filePath}, |
| | | </if> |
| | | <if test="downloadPath != null"> |
| | | #{downloadPath}, |
| | | </if> |
| | | <if test="dt != null"> |
| | | #{dt}, |
| | |
| | | <if test="filePath != null"> |
| | | file_path = #{filePath}, |
| | | </if> |
| | | <if test="downloadPath != null"> |
| | | download_path = #{downloadPath}, |
| | | </if> |
| | | <if test="dt != null"> |
| | | dt = #{dt}, |
| | | </if> |
| | |
| | | new_name = #{newName}, |
| | | hash = #{hash}, |
| | | file_path = #{filePath}, |
| | | download_path = #{downloadPath}, |
| | | dt = #{dt} |
| | | where id = #{id} |
| | | </update> |
| | |
| | | public String fileSysRelativePath; //文件名称的哈希值对应的文件最终存储相对路径的目录,在配置文件中配置 |
| | | public String restUrl;//文件系统路径 |
| | | public String webUrl ;//下载文档的web路径 |
| | | public String webDownloadUrl ;//Action下载文档的web路径 |
| | | public String webDownloadPath ;//下载文档的Controller的相对路径 |
| | | public Integer hashStart ;//哈希值启始值(包含) |
| | | public Integer hashEnd ;//哈希值截止值(包含) |
| | | |
| | |
| | | String fileSysBasePath, |
| | | String restUrl, |
| | | String webUrl, |
| | | String webDownloadUrl, |
| | | String webDownloadPath, |
| | | Integer hashStart, |
| | | Integer hashEnd)throws Exception{ |
| | | this.id = id ; |
| | |
| | | this.fileSysRelativePath = fileSysBasePath ; |
| | | this.restUrl = restUrl ; |
| | | this.webUrl = webUrl ; |
| | | this.webDownloadUrl = webDownloadUrl ; |
| | | this.webDownloadPath = webDownloadPath ; |
| | | this.hashStart = hashStart ; |
| | | this.hashEnd = hashEnd ; |
| | | if(this.id == null || this.id.trim().equals("")){ |
| | |
| | | this.webUrl += "/" ; |
| | | } |
| | | } |
| | | if(this.webDownloadUrl == null || this.webDownloadUrl.trim().equals("")){ |
| | | throw new Exception("出错,webDownloadUrl为空了!") ; |
| | | if(this.webDownloadPath == null || this.webDownloadPath.trim().equals("")){ |
| | | throw new Exception("出错,webDownloadPath!") ; |
| | | } |
| | | |
| | | if(this.hashStart == null){ |
| | |
| | | + "fileSysBasePath=" + fileSysRelativePath + "\n" |
| | | + "restUrl=" + restUrl + "\n" |
| | | + "webUrl=" + webUrl + "\n" |
| | | + "webDownloadUrl=" + webDownloadUrl + "\n" |
| | | + "webDownloadPath=" + webDownloadPath + "\n" |
| | | + "hashStart=" + hashStart + "\n" |
| | | + "hashEnd=" + hashEnd ; |
| | | } |
| | |
| | | String hashEnd = env.getProperty("dy.webFile.sv" + i + ".hashEnd"); |
| | | String restUrl = env.getProperty("dy.webFile.sv" + i + ".restUrl"); |
| | | String webUrl = env.getProperty("dy.webFile.sv" + i + ".webUrl"); |
| | | String webDownloadUrl = env.getProperty("dy.webFile.sv" + i + ".webDownloadUrl"); |
| | | String webDownloadPath = env.getProperty("dy.webFile.sv" + i + ".webDownloadPath"); |
| | | if(!NumUtil.isPlusIntNumber(hashStart)){ |
| | | throw new Exception("配置dy.webFile.sv" + i + ".hashStart 不是整数") ; |
| | | } |
| | |
| | | relativePath, |
| | | restUrl, |
| | | webUrl, |
| | | webDownloadUrl, |
| | | webDownloadPath, |
| | | Integer.parseInt(hashStart), |
| | | Integer.parseInt(hashEnd))) ; |
| | | } |
| | |
| | | public String fileSysRelativePath; //文件名称的哈希值对应的文件最终存储相对路径的目录,在配置文件中配置 |
| | | public String fileSysRestUrl; //文件名称的哈希值对应的文件系统的restful URL,在配置文件中配置 |
| | | public String fileWebUrl; //文件名称的哈希值对应的文件系统的下载文件的web URL,在配置文件中配置 |
| | | public String fileWebDownloadUrl; //文件名称的哈希值对应的文件系统的Action下载文件的web URL,在配置文件中配置 |
| | | public String fileWebDownloadPath; //下载文档的Controller的相对路径 |
| | | |
| | | public String toString(){ |
| | | return "fileName=" + fileName + "\n" |
| | |
| | | + "fileSysRelativePath=" + fileSysRelativePath + "\n" |
| | | + "restUrl=" + fileSysRestUrl + "\n" |
| | | + "fileWebUrl=" + fileWebUrl + "\n" |
| | | + "fileWebDownloadUrl=" + fileWebDownloadUrl ; |
| | | + "fileWebDownloadPath=" + fileWebDownloadPath ; |
| | | } |
| | | |
| | | } |
| | |
| | | rvo.fileSysRelativePath = confVo.fileSysRelativePath; |
| | | rvo.fileSysRestUrl = confVo.restUrl; |
| | | rvo.fileWebUrl = confVo.webUrl ; |
| | | rvo.fileWebDownloadUrl = confVo.webDownloadUrl ; |
| | | rvo.fileWebDownloadPath = confVo.webDownloadPath ; |
| | | } |
| | | } |
| | | } |
| | |
| | | rvo.fileSysRelativePath = confVo.fileSysRelativePath; |
| | | rvo.fileSysRestUrl = confVo.restUrl; |
| | | rvo.fileWebUrl = confVo.webUrl ; |
| | | rvo.fileWebDownloadUrl = confVo.webDownloadUrl ; |
| | | rvo.fileWebDownloadPath = confVo.webDownloadPath ; |
| | | } |
| | | } |
| | | } |