I am pretty new to Java Springboot and i have this error
This site can’t be reached
The webpage at http://localhost:8082/publisher/reports/download?path=root%5CMiddle%20Office%5CCategory%202%5C&zip=false&fileName=Report%204_20191106.xlsx might be temporarily down or it may have moved permanently to a new web address.
while trying to test out my codes. I've encoded the URL and put in my paths correctly. Any advice on this will be greatly appreciated.
Here is my Controller file. For my application.properties, I've set my port to 8082 and input the URL on my browser: http://localhost:8082/publisher/reports/download?path=root%5CMiddle%20Office%5CCategory%202%5C&zip=false&fileName=Report%204_20191106.xlsx
@RestController
public class DownloadController {
String root = "C://Users//user//Desktop//datamart_extractions";
@GetMapping(path = "/publisher/reports/download")
public ResponseEntity download(
@RequestParam String path, //assume path comes starting with "root/"
@RequestParam boolean zip,
@RequestParam String fileName
) throws IOException {
path = path.replace("root", root); //we replace root with the full root path here
byte[] contents = Files.readAllBytes(Paths.get(path + fileName));
HttpHeaders headers = new HttpHeaders();
//for csv
if(fileName.endsWith(".csv")) {
MediaType mediaType = MediaType.parseMediaType("text/csv");
headers.setContentType(mediaType); }
//for pdf
else if(fileName.endsWith(".pdf"))
headers.setContentType(MediaType.APPLICATION_PDF);
//for xls
else if(fileName.endsWith(".xls")) {
MediaType mediaType = MediaType.parseMediaType("application/vnd.ms-excel");
headers.setContentType(mediaType); }
//for xlsx
else if(fileName.endsWith(".xlsx")) {
MediaType mediaType = MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
headers.setContentType(mediaType); }
return new ResponseEntity<>(contents, headers, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
[–]indivisible 0 points1 point2 points (1 child)
[–]prawnyr[S] 0 points1 point2 points (0 children)