Commit cbb3f91b by liuyang

2024-06-21 附件预览

parent 98f1ce71
package com.baosight.hggp.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baosight.hggp.core.tools.ThreadLocalTools;
import com.baosight.hggp.util.FileUtils;
import com.baosight.hggp.util.LogUtils;
import com.baosight.hggp.util.MapUtils;
import com.baosight.hggp.util.StringUtils;
import com.baosight.iplat4j.config.AdminFactoryConfig;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.exception.PlatException;
import com.baosight.iplat4j.core.service.soa.XServiceManager;
import com.baosight.iplat4j.eu.dm.document.bos.s3.api.signed.SignedBosHelp;
import com.baosight.iplat4j.eu.dm.document.bos.s3.param.BosParamHelp;
import com.baosight.iplat4j.eu.dm.util.IFileUploader;
import com.google.common.base.Joiner;
import org.activiti.engine.impl.util.json.JSONString;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -19,8 +25,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.io.*;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
......@@ -39,7 +44,7 @@ import lombok.extern.slf4j.Slf4j;
@CrossOrigin
@RequestMapping({"/file/download"})
public class FileDownloadController {
/**
* 更具docId下载文件
*
......@@ -81,7 +86,22 @@ public class FileDownloadController {
response.getWriter().write(msg);
}
}
@RequestMapping({"docId/{docId}"})
public void downloadUrls(@PathVariable String docId, HttpServletRequest request, HttpServletResponse response) throws IOException {
String docJson = AdminFactoryConfig.getFileUpLoadInterface().getDocJSONById(docId);
Map document = (Map) JSON.parseObject(docJson, Map.class);
String docName = document.get("docName").toString();
String chgName = document.get("chgName").toString();
String docPath = document.get("realPath").toString();
String filePath = docPath + "/" + chgName;
try {
this.httpDownload(response, filePath, docName);
} catch (Exception e) {
String msg = String.format("下载文件【%s】失败!原因:%s", docId, LogUtils.getMsg(e));
response.getWriter().write(msg);
}
}
private String getReturnUrlByParam(Map<String, String[]> parameterMap, String returnUrl)
throws UnsupportedEncodingException {
String returnUrl2 = "";
......@@ -138,5 +158,63 @@ public class FileDownloadController {
}
return strBuilder.toString();
}
private void httpDownload(HttpServletResponse response, String filePath, String downloadFileName) throws Exception {
File file = new File(filePath);
FileInputStream fileInputStream = new FileInputStream(file);
Throwable var6 = null;
try {
OutputStream outputStream = response.getOutputStream();
Throwable var8 = null;
try {
downloadFileName = URLEncoder.encode(downloadFileName, "UTF-8");
downloadFileName = downloadFileName.replaceAll("\\+", "%20");
response.reset();
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename*=utf-8''" + downloadFileName);
byte[] buffer = new byte[1024];
int i;
while((i = fileInputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, i);
}
} catch (Throwable var32) {
var8 = var32;
throw var32;
} finally {
if (outputStream != null) {
if (var8 != null) {
try {
outputStream.close();
} catch (Throwable var31) {
var8.addSuppressed(var31);
}
} else {
outputStream.close();
}
}
}
} catch (Throwable var34) {
var6 = var34;
throw var34;
} finally {
if (fileInputStream != null) {
if (var6 != null) {
try {
fileInputStream.close();
} catch (Throwable var30) {
var6.addSuppressed(var30);
}
} else {
fileInputStream.close();
}
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment