Commit 46e11868 by liyanlin

fix

parent 612c585f
......@@ -19,11 +19,14 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.List;
......@@ -85,9 +88,20 @@ public class CostPlanController {
GetCostPlanResp byPlanNo = costPlanService.getByPlanNo(costPlanNo);
String filePath = byPlanNo.getCostPlan().getFilePath();
String fileName = byPlanNo.getFileName();
InputStream inputStream;
long contentLength = 0;
if(filePath.startsWith("http")){
fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
RestTemplate restTemplate = new RestTemplate();
byte[] bytes = restTemplate.getForObject(filePath, byte[].class);
inputStream = new ByteArrayInputStream(bytes);
contentLength = bytes.length;
}else{
FileSystemResource file = new FileSystemResource(filePath);
contentLength = file.contentLength();
inputStream = file.getInputStream();
}
HttpHeaders headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
// new String(fileName.getBytes("UTF-8"),"iso-8859-1") 解决文件下载的时候文件名乱码的问题
......@@ -98,8 +112,8 @@ public class CostPlanController {
return ResponseEntity
.ok()
.headers(headers)
.contentLength(file.contentLength())
.contentLength(contentLength)
.contentType(MediaType.parseMediaType("application/octet-stream"))
.body(new InputStreamResource(file.getInputStream()));
.body(new InputStreamResource(inputStream));
}
}
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