Commit c2a1ca37 authored by 廖旭伟's avatar 廖旭伟

素材分组接口bug修改

parent e1d01e15
...@@ -3248,3 +3248,115 @@ msg|String|消息|- ...@@ -3248,3 +3248,115 @@ msg|String|消息|-
} }
``` ```
## 文件处理
### 上传文件
**请求URL:** file/upload
**请求方式:** POST
**内容类型:** application/json;charset=utf-8
**简要描述:** 上传文件
**请求参数:**
参数名称|类型|必填|描述
:---|:---|:---|:-------
uploadFile|File|是|文件
prePath|String|否|存放子文件夹名称
**请求样例:**
```
{
"uploadFile":"v3egpq",
"prePath":"194smx"
}
**响应参数:**
参数名称 |参数类型|备注|其它
---|---|---|---
code|Integer|结果码(-1.失败,1.成功)|-
msg|String|消息|-
**响应消息样例:**
```
{
"code":1,
"msg":"成功"
}
```
### 下载文件
**请求URL:** file/common/download
**请求方式:** GET
**内容类型:** application/json;charset=utf-8
**简要描述:** 删除图片分组
**请求参数:**
参数名称|类型|必填|描述
:---|:---|:---|:------
fileName|String|是|文件名
**请求样例:**
```
http://localhost:8080/eas/file/common/download?fileName=test/2b1a70e34b88405893a7ff1f6db947cc.jpg'
```
**响应参数:**
参数名称 |参数类型|备注|其它
---|---|---|---
code|Integer|结果码(-1.失败,1.成功)|-
msg|String|消息|-
**响应消息样例:**
```
{
"code":1,
"msg":"成功"
}
```
### 预览图片
**请求URL:** file/preview
**请求方式:** GET
**内容类型:** application/json;charset=utf-8
**简要描述:** 删除图片分组
**请求参数:**
参数名称|类型|必填|描述
:---|:---|:---|:------
fileName|String|是|文件名
**请求样例:**
```
http://localhost:8080/eas/file/preview/test/2b1a70e34b88405893a7ff1f6db947cc.jpg
```
**响应参数:**
参数名称 |参数类型|备注|其它
---|---|---|---
code|Integer|结果码(-1.失败,1.成功)|-
msg|String|消息|-
**响应消息样例:**
```
{
"code":1,
"msg":"成功"
}
```
\ No newline at end of file
...@@ -16,7 +16,9 @@ import org.springframework.http.MediaType; ...@@ -16,7 +16,9 @@ import org.springframework.http.MediaType;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
...@@ -103,14 +105,28 @@ public class UploadServiceImpl implements UploadService { ...@@ -103,14 +105,28 @@ public class UploadServiceImpl implements UploadService {
@Override @Override
public void preview(String fileName, HttpServletResponse response) { public void preview(String fileName, HttpServletResponse response) {
String filePath = this.filePath+"/preview/" + fileName; // String filePath = this.filePath+"/preview/" + fileName;
// try {
// response.setContentType(MediaType.IMAGE_JPEG_VALUE);
// setAttachmentResponseHeader(response, fileName);
// FileUtil.writeToStream(filePath, response.getOutputStream());
// } catch (Exception e) {
// log.error("下载文件失败", e);
// }
String filePath = getFilePath(fileName);
try { try {
response.setContentType(MediaType.IMAGE_JPEG_VALUE); File file = new File(filePath);
setAttachmentResponseHeader(response, fileName); BufferedImage image = (BufferedImage) ImageIO.read(file);
FileUtil.writeToStream(filePath, response.getOutputStream()); response.setHeader("Pragma", "No-cache");
} catch (Exception e) { response.setHeader("Cache-Control", "No-cache");
log.error("下载文件失败", e); response.setDateHeader("Expires", 0L);
response.setContentType("image/jpeg");
ImageIO.write(image, "JPEG", response.getOutputStream());
} catch (Exception var4) {
this.log.debug("响应图片消息异常-->" + var4.getMessage());
} }
} }
......
...@@ -94,6 +94,20 @@ public class UploadController extends BaseController { ...@@ -94,6 +94,20 @@ public class UploadController extends BaseController {
} }
} }
/**
* 图片预览 (PathVariable)
*
* @param fileName 文件名称
*/
@GetMapping("preview/{prePath}/{fileName}")
public void preViewPath(@PathVariable(value="fileName") String fileName,@PathVariable(value="prePath") String prePath, HttpServletResponse response) {
try {
uploadService.preview(prePath+"/"+fileName, response);
} catch (Exception e) {
log.error("下载文件失败:", e);
}
}
/** /**
* 图片预览 (PathVariable) * 图片预览 (PathVariable)
* *
......
...@@ -34,8 +34,8 @@ mybatis: ...@@ -34,8 +34,8 @@ mybatis:
application: application:
auth: auth:
unloginUrl: /refresh,/error,/login/login,/login/index,/login/logout,/securitycode/createCode,/file/common/*,/test*,/api/asset/*,/api/*,/zwfw/*,/ws/*,/swagger-ui*,/topic/*,/uploads/* unloginUrl: /refresh,/error,/login/login,/login/index,/login/logout,/customer/login/login,customer/login/logout,/securitycode/createCode,/file/common/*,/file/preview/*,/test*,/api/asset/*,/api/*,/zwfw/*,/ws/*,/swagger-ui*,/topic/*,/uploads/*
uncheckUrl: /refresh,/error,/login/login,/login/index,/login/logout,/securitycode/createCode,/file/common/*,/test*,/api/asset/*,/api/*,/zwfw/*,/ws/*,/swagger-ui*,/topic/*,/uploads/* uncheckUrl: /refresh,/error,/login/login,/login/index,/login/logout,/customer/login/login,customer/login/logout,/securitycode/createCode,/file/common/*,/file/preview/*,/test*,/api/asset/*,/api/*,/zwfw/*,/ws/*,/swagger-ui*,/topic/*,/uploads/*
workflow: workflow:
tenantId: ${spring.application.name} tenantId: ${spring.application.name}
token: token:
......
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