You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
udi-wms-java/src/main/java/com/glxp/api/upload/ImageController.java

47 lines
1.5 KiB
Java

package com.glxp.api.upload;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
@RestController
public class ImageController {
@Value("${file_path}")
private String filePath;
@GetMapping(value = "/spms/donwload/pdf")
public void downloadPdf(HttpServletResponse response,
@RequestParam String fileName) throws IOException {
OutputStream os = null;
try {
FileInputStream input = new FileInputStream(new File(filePath + "/pdfprint/" + fileName));
response.setDateHeader("Expires", 0);
response.setHeader("Content-disposition", "inline; filename=" + "export.pdf");
response.setContentType("application/pdf; charset=utf-8");
OutputStream out = response.getOutputStream();
// JasperExportManager.exportReportToPdfStream(input,out);
byte[] b = new byte[2048];
int len;
while ((len = input.read(b)) != -1) {
out.write(b, 0, len);
}
input.close();
} catch (IOException e) {
} finally {
if (os != null) {
os.flush();
os.close();
}
}
}
}