项目和文件不在同一个服务器,a标签下载文件无法解决文件名过长报错的情况,所以只能通过后台下载设置文件名。
也就是用户不是直接通过文件服务器下载,而是先经过后台,后台从文件服务器读取该文件,然后在写给用户。
@RequestMapping("downloadFile")
public void download(String id, HttpServletResponse response){
//获取该文件的名称、后缀
SysFile sysFile = sysFileService.selectById(id);
//文件在服务器的路径
String path = ConstantFactory.me().getfdfsStorage()+sysFile.getGroup()+"/"+sysFile.getPath();
InputStream inputStream = null;
OutputStream out = null;
try {
//根据文件在服务器的路径读取该文件转化为流
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5 * 1000);
inputStream = conn.getInputStream();
//创建一个Buffer字符串
byte[] buffer = new