fixbug 文件上传大小 && 微信https 异常问题
This commit is contained in:
@@ -5,12 +5,18 @@ import com.sv.dto.app.VenueLessonStatus;
|
||||
import com.sv.entity.Venue;
|
||||
import com.sv.service.api.VenueLessonService;
|
||||
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.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
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.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -22,6 +28,10 @@ public class AppVenueLessonController {
|
||||
private VenueService venueService;
|
||||
@Resource
|
||||
private VenueLessonService venueLessonService;
|
||||
@Value("${oss.url}")
|
||||
private String url;
|
||||
@Value("${sv.file.store.health}")
|
||||
private String healthDir;
|
||||
|
||||
/**
|
||||
* 通过返回页面来进行拼接,每个APP可以返回具体的场馆的课程预订情况
|
||||
@@ -138,4 +148,26 @@ public class AppVenueLessonController {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,12 +3,15 @@ package com.sv.oms.controller;
|
||||
import com.sv.service.common.OSSClientUtil;
|
||||
import com.ydd.framework.core.common.dto.ResponseDTO;
|
||||
import com.ydd.oms.controller.OmsController;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
|
||||
@RestController("upload")
|
||||
@@ -52,7 +55,9 @@ public class UploadController extends OmsController {
|
||||
* @return
|
||||
*/
|
||||
@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);
|
||||
return ResponseDTO.ok().addAttribute("docPath",healthUrl);
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ app:
|
||||
spring:
|
||||
http:
|
||||
multipart:
|
||||
max-file-size: 40MB
|
||||
max-request-size: 40MB
|
||||
max-file-size: 1024MB
|
||||
max-request-size: 1024MB
|
||||
enabled: true
|
||||
profiles:
|
||||
include:
|
||||
|
||||
@@ -119,19 +119,21 @@ public class OSSClientUtil {
|
||||
ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
|
||||
String substring = originalFilename.substring(originalFilename.lastIndexOf(".")).toLowerCase();
|
||||
String name = UUIDGenerator.randomUUID() + substring;
|
||||
backUrl = healthDir + name;
|
||||
String uploadUrl = healthDir + name;
|
||||
// 上传文件
|
||||
ossClient.putObject(bucketName, backUrl, multipartFile.getInputStream());
|
||||
ossClient.setObjectAcl(bucketName, backUrl, CannedAccessControlList.PublicRead);
|
||||
ossClient.putObject(bucketName, uploadUrl, multipartFile.getInputStream());
|
||||
ossClient.setObjectAcl(bucketName, uploadUrl, CannedAccessControlList.PublicRead);
|
||||
// 判断是否上传成功
|
||||
boolean uploadResult = ossClient.doesObjectExist(bucketName, backUrl);
|
||||
boolean uploadResult = ossClient.doesObjectExist(bucketName, uploadUrl);
|
||||
|
||||
if (uploadResult) {
|
||||
backUrl = getUploadUrl(name);
|
||||
} else {
|
||||
backUrl = "";
|
||||
}
|
||||
} finally {
|
||||
} catch (Exception ex) {
|
||||
log.error("upload error",ex);
|
||||
}finally {
|
||||
if (ossClient != null) {
|
||||
ossClient.shutdown();
|
||||
}
|
||||
@@ -139,10 +141,12 @@ public class OSSClientUtil {
|
||||
return backUrl;
|
||||
}
|
||||
|
||||
private String getUploadUrl(String fileUrl) {
|
||||
if (!StringUtils.isEmpty(fileUrl)) {
|
||||
String[] split = fileUrl.split("/");
|
||||
return url + this.healthDir + split[split.length - 1];
|
||||
private String getUploadUrl(String fileName) {
|
||||
if (!StringUtils.isEmpty(fileName)) {
|
||||
// String[] split = fileUrl.split("/");
|
||||
// return this.healthDir + split[split.length - 1];
|
||||
String result = "https://api.hongyutiyu.top/fetchFile/" + fileName;
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user