@Service
public class FileService {
@Autowired
private ResourceLoader resourceLoader;
private static final String PATH = "classpath:/static/files/catalogs/";
public ResponseEntity<Resource> download(HttpServletRequest request, String path, String filename) {
try {
Resource resource = resourceLoader.getResource(PATH + path + "/" + filename);
return ResponseEntity.ok()
// .header(HttpHeaders.CONTENT_DISPOSITION, "attach; filename=\"" + filename +
// "\"")
.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + filename + "\"")
// .header(HttpHeaders.CONTENT_TYPE,
// MediaType.APPLICATION_OCTET_STREAM.toString())
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_PDF.toString())
.body(resource);
} catch (Exception e) {
// e.printStackTrace();
System.out.println("파일 에러");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
}
end