| | |
| | | import org.apache.shiro.authz.annotation.RequiresPermissions; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.springframework.web.multipart.MultipartHttpServletRequest; |
| | | import org.springframework.web.multipart.commons.CommonsMultipartResolver; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.io.PrintWriter; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * APP版本管理 |
| | |
| | | return ApiResponse.success(appVersionService.findById(id)); |
| | | } |
| | | |
| | | @ApiOperation("上传APP文件") |
| | | @PostMapping(value = "/uploadFile", headers = "content-type=multipart/form-data") |
| | | public void uploadFile(HttpServletRequest request, HttpServletResponse response) throws Exception { |
| | | Map<String, Object> context = new HashMap<>(); |
| | | try { |
| | | CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(); |
| | | if (multipartResolver.isMultipart(request)) { |
| | | MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; |
| | | Iterator<String> it = multipartRequest.getFileNames(); |
| | | while (it.hasNext()) { |
| | | MultipartFile file = multipartRequest.getFile(it.next()); |
| | | if (file != null && !file.isEmpty()) { |
| | | Map<String, Object> data = appVersionService.uploadFile(file); |
| | | context.put("success", true); |
| | | context.put("code", 200); |
| | | context.put("errno", 0); |
| | | context.put("data", data); |
| | | context.put("message", "请求成功"); |
| | | response.setCharacterEncoding("UTF-8"); |
| | | response.setContentType("application/json"); |
| | | PrintWriter out = response.getWriter(); |
| | | out.print(com.alibaba.fastjson.JSONObject.toJSONString(context)); |
| | | out.flush(); |
| | | out.close(); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | context.put("code", 0); |
| | | context.put("message", "上传失败"); |
| | | } |
| | | response.setCharacterEncoding("UTF-8"); |
| | | response.setContentType("application/json"); |
| | | PrintWriter out = response.getWriter(); |
| | | out.print(com.alibaba.fastjson.JSONObject.toJSONString(context)); |
| | | out.flush(); |
| | | out.close(); |
| | | } |
| | | |
| | | } |