我有一个 pbf 文件,如 this我想用 spring boot 2.2.2.RELEASE 来回应它完整的应用程序。 Mapbox响应服务器如下,我想用spring boot实现它:
Mapbox Content-Type 是 application/x-protobuf
,我怎样才能在 Spring Boot Restfull 应用程序中做到这一点?
最佳答案
可以这样下载
@RestController
@RequestMapping("/api")
public class DownloadsController {
@GetMapping("/getFile")
public ResponseEntity<Resource> getFile(HttpServletResponse httpServletResponse) throws FileNotFoundException{
File file = new File("/home/sagara/Downloads/3.vector.pbf");
HttpHeaders headers = new HttpHeaders();
String fileName = file.getName();
headers.add("Content-disposition","attachment; filename="+ fileName);
Resource resource = new InputStreamResource(new FileInputStream(file));
return ResponseEntity.ok()
.headers(headers)
.contentLength(file.length())
.contentType(MediaType.parseMediaType("application/x-protobuf"))
.body(resource);
}
}
关于java - 如何在Spring Boot Restful应用程序中响应pbf文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59465862/