fixbug 文件上传大小 && 微信https 异常问题

This commit is contained in:
limqhz
2021-03-28 12:52:21 +08:00
parent 3fa693bf01
commit dbf34c9fd1
4 changed files with 54 additions and 13 deletions

View File

@@ -5,12 +5,18 @@ import com.sv.dto.app.VenueLessonStatus;
import com.sv.entity.Venue; import com.sv.entity.Venue;
import com.sv.service.api.VenueLessonService; import com.sv.service.api.VenueLessonService;
import com.sv.service.oms.VenueService; import com.sv.service.oms.VenueService;
import org.apache.http.client.fluent.Request;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -22,6 +28,10 @@ public class AppVenueLessonController {
private VenueService venueService; private VenueService venueService;
@Resource @Resource
private VenueLessonService venueLessonService; private VenueLessonService venueLessonService;
@Value("${oss.url}")
private String url;
@Value("${sv.file.store.health}")
private String healthDir;
/** /**
* 通过返回页面来进行拼接每个APP可以返回具体的场馆的课程预订情况 * 通过返回页面来进行拼接每个APP可以返回具体的场馆的课程预订情况
@@ -138,4 +148,26 @@ public class AppVenueLessonController {
return venueItems; return venueItems;
} }
/**
* 查询数据库
*/
@RequestMapping(value = "/fetchFile/{fileUrl}", method = {RequestMethod.GET,RequestMethod.POST})
public void fetchFile(String fileUrl, HttpServletResponse response) throws IOException {
String findFile = url + healthDir + fileUrl;
InputStream inputStream = Request.Get(findFile).execute().returnContent().asStream();
ServletOutputStream servletOutputStream = response.getOutputStream();
if (inputStream != null && servletOutputStream != null) {
int temp = 0;
// 开始拷贝
while ((temp = inputStream.read()) != -1) {
// 边读边写
servletOutputStream.write(temp);
}
// 关闭输入输出流
inputStream.close();
servletOutputStream.flush();
servletOutputStream.close();
}
}
} }

View File

@@ -3,12 +3,15 @@ package com.sv.oms.controller;
import com.sv.service.common.OSSClientUtil; import com.sv.service.common.OSSClientUtil;
import com.ydd.framework.core.common.dto.ResponseDTO; import com.ydd.framework.core.common.dto.ResponseDTO;
import com.ydd.oms.controller.OmsController; import com.ydd.oms.controller.OmsController;
import org.apache.http.HttpRequest;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException; import java.io.IOException;
@RestController("upload") @RestController("upload")
@@ -52,7 +55,9 @@ public class UploadController extends OmsController {
* @return * @return
*/ */
@RequestMapping(value = "/uploadFile") @RequestMapping(value = "/uploadFile")
public ResponseDTO uploadFile(@RequestParam("file") MultipartFile multipartFile) throws IOException { public ResponseDTO uploadFile(HttpServletRequest request) throws IOException {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
MultipartFile multipartFile = multipartRequest.getFile("file");
String healthUrl = ossClientUtil.uploadHealth(multipartFile); String healthUrl = ossClientUtil.uploadHealth(multipartFile);
return ResponseDTO.ok().addAttribute("docPath",healthUrl); return ResponseDTO.ok().addAttribute("docPath",healthUrl);
} }

View File

@@ -11,8 +11,8 @@ app:
spring: spring:
http: http:
multipart: multipart:
max-file-size: 40MB max-file-size: 1024MB
max-request-size: 40MB max-request-size: 1024MB
enabled: true enabled: true
profiles: profiles:
include: include:
@@ -93,4 +93,4 @@ logging:
level: level:
com: com:
sv: sv:
mapper: DEBUG mapper: DEBUG

View File

@@ -119,19 +119,21 @@ public class OSSClientUtil {
ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret); ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
String substring = originalFilename.substring(originalFilename.lastIndexOf(".")).toLowerCase(); String substring = originalFilename.substring(originalFilename.lastIndexOf(".")).toLowerCase();
String name = UUIDGenerator.randomUUID() + substring; String name = UUIDGenerator.randomUUID() + substring;
backUrl = healthDir + name; String uploadUrl = healthDir + name;
// 上传文件 // 上传文件
ossClient.putObject(bucketName, backUrl, multipartFile.getInputStream()); ossClient.putObject(bucketName, uploadUrl, multipartFile.getInputStream());
ossClient.setObjectAcl(bucketName, backUrl, CannedAccessControlList.PublicRead); ossClient.setObjectAcl(bucketName, uploadUrl, CannedAccessControlList.PublicRead);
// 判断是否上传成功 // 判断是否上传成功
boolean uploadResult = ossClient.doesObjectExist(bucketName, backUrl); boolean uploadResult = ossClient.doesObjectExist(bucketName, uploadUrl);
if (uploadResult) { if (uploadResult) {
backUrl = getUploadUrl(name); backUrl = getUploadUrl(name);
} else { } else {
backUrl = ""; backUrl = "";
} }
} finally { } catch (Exception ex) {
log.error("upload error",ex);
}finally {
if (ossClient != null) { if (ossClient != null) {
ossClient.shutdown(); ossClient.shutdown();
} }
@@ -139,10 +141,12 @@ public class OSSClientUtil {
return backUrl; return backUrl;
} }
private String getUploadUrl(String fileUrl) { private String getUploadUrl(String fileName) {
if (!StringUtils.isEmpty(fileUrl)) { if (!StringUtils.isEmpty(fileName)) {
String[] split = fileUrl.split("/"); // String[] split = fileUrl.split("/");
return url + this.healthDir + split[split.length - 1]; // return this.healthDir + split[split.length - 1];
String result = "https://api.hongyutiyu.top/fetchFile/" + fileName;
return result;
} }
return null; return null;
} }