如何在 spring 启动 restful 应用程序时响应 pbf 文件?
How response pbf file in spring boot restful application?
我有一个类似 this and I want to response it with spring boot 2.2.2.RELEASE resfull 应用程序的 pbf 文件。 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);
}
}
我有一个类似 this and I want to response it with spring boot 2.2.2.RELEASE resfull 应用程序的 pbf 文件。 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);
}
}