|
@@ -27,9 +27,13 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.multipart.MultipartRequest;
|
|
|
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.OutputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -1186,6 +1190,37 @@ public class UniversalController extends BaseRESTfulController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation("获取图片通用方法")
|
|
|
+ @GetMapping("/getFile")
|
|
|
+ public RESTfulResult getFile(@RequestParam("path") String path, HttpServletResponse response) throws Exception {
|
|
|
+ try {
|
|
|
+ File file = new File(path);
|
|
|
+ if(file.isDirectory()){
|
|
|
+ return failed("该路径是文件夹而非文件!");
|
|
|
+ }
|
|
|
+ FileInputStream inputStream = new FileInputStream(path);
|
|
|
+ byte[] data = new byte[inputStream.available()];
|
|
|
+ inputStream.read(data);
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ response.setContentType("application/octet-stream;charset=UTF-8");
|
|
|
+ String diskfilename = URLEncoder.encode(file.getName(),"UTF-8") ;
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=\"" + diskfilename + "\"");
|
|
|
+ response.setContentLength(data.length);
|
|
|
+ response.setHeader("Content-Range", "" + Integer.valueOf(data.length - 1));
|
|
|
+ response.setHeader("Accept-Ranges", "bytes");
|
|
|
+ OutputStream os = response.getOutputStream();
|
|
|
+ os.write(data);
|
|
|
+ //先声明的流后关掉!
|
|
|
+ os.flush();
|
|
|
+ os.close();
|
|
|
+ inputStream.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return failed("未知异常!",e.getMessage());
|
|
|
+ }
|
|
|
+ return success("成功!");
|
|
|
+ }
|
|
|
+
|
|
|
@ApiOperation("上传图片通用方法,返回成功后的url")
|
|
|
@PostMapping("/uploadPic")
|
|
|
public String getPicture(MultipartRequest request) throws Exception {
|