Commit f6562d2b authored by yanzg's avatar yanzg

参数处理

parent 7b6b23da
package com.yanzuoguang.util.helper; package com.yanzuoguang.util.helper;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.exception.HttpCodeException; import com.yanzuoguang.util.exception.HttpCodeException;
import com.yanzuoguang.util.thread.ProcessData; import com.yanzuoguang.util.thread.ProcessData;
import com.yanzuoguang.util.thread.RunProcess; import com.yanzuoguang.util.thread.RunProcess;
import javax.xml.ws.http.HTTPException;
import java.io.*; import java.io.*;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
......
...@@ -2,6 +2,9 @@ package com.yanzuoguang.cloud.file; ...@@ -2,6 +2,9 @@ package com.yanzuoguang.cloud.file;
import com.yanzuoguang.cloud.file.vo.*; import com.yanzuoguang.cloud.file.vo.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/** /**
* 文件上传路径 * 文件上传路径
* *
...@@ -24,6 +27,15 @@ public interface YzgFileService { ...@@ -24,6 +27,15 @@ public interface YzgFileService {
*/ */
void removeTempFolder(String tempFolder); void removeTempFolder(String tempFolder);
/**
* 下载文件
*
* @param fromUrl 服务其文件路径
* @param response 输出流
* @throws IOException
*/
void down(String fromUrl, HttpServletResponse response) throws IOException;
/** /**
* 移动文件或文件夹 * 移动文件或文件夹
* *
......
package com.yanzuoguang.cloud.helper; package com.yanzuoguang.cloud.helper;
import com.yanzuoguang.util.helper.HttpHelper; import com.yanzuoguang.util.helper.HttpHelper;
import com.yanzuoguang.util.helper.StringHelper;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
...@@ -25,6 +26,10 @@ public class HttpFileHelper extends HttpHelper { ...@@ -25,6 +26,10 @@ public class HttpFileHelper extends HttpHelper {
public static void localToDown(String serverFilePath, String saveFileName, HttpServletResponse response) throws IOException { public static void localToDown(String serverFilePath, String saveFileName, HttpServletResponse response) throws IOException {
//获取文件的长度 //获取文件的长度
File file = new File(serverFilePath); File file = new File(serverFilePath);
if (StringHelper.isEmpty(saveFileName)) {
File parentFile = file.getParentFile();
saveFileName = StringHelper.trimLeft(file.getAbsolutePath().substring(parentFile.getAbsolutePath().length()), "/");
}
//设置文件输出类型 //设置文件输出类型
response.setContentType("application/octet-stream"); response.setContentType("application/octet-stream");
......
package com.yanzuoguang.cloud.file; package com.yanzuoguang.cloud.file;
import com.yanzuoguang.cloud.file.vo.*; import com.yanzuoguang.cloud.file.vo.*;
import com.yanzuoguang.cloud.helper.HttpFileHelper;
import com.yanzuoguang.util.MediaHelper; import com.yanzuoguang.util.MediaHelper;
import com.yanzuoguang.util.MediaParameter; import com.yanzuoguang.util.MediaParameter;
import com.yanzuoguang.util.cache.MemoryCache; import com.yanzuoguang.util.cache.MemoryCache;
import com.yanzuoguang.util.exception.CodeException; import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.DateHelper; import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.helper.FileHelper; import com.yanzuoguang.util.helper.FileHelper;
import com.yanzuoguang.util.helper.HttpHelper;
import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.helper.StringHelper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
...@@ -116,6 +119,28 @@ public class YzgFileServiceImpl implements YzgFileService { ...@@ -116,6 +119,28 @@ public class YzgFileServiceImpl implements YzgFileService {
} }
} }
/**
* 下载文件
*
* @param fromUrl
* @param response
*/
@Override
public void down(String fromUrl, HttpServletResponse response) throws IOException {
checkFolder(fromUrl);
String fromFullUrl = fileConfig.getServerFullPath(fromUrl);
// 父文件夹不存在子文件时则删除
File file = new File(fromFullUrl);
if (file.exists()) {
throw new CodeException("文件不存在");
}
if (file.isDirectory()) {
throw new CodeException("文件是目录");
}
HttpFileHelper.localToDown(fromFullUrl, StringHelper.EMPTY, response);
}
/** /**
* 移动文件或文件夹 * 移动文件或文件夹
* *
......
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