0

我有一个这样的 pbf 文件,我想用spring boot 2.2.2.RELEASE resfull 应用程序来响应它。Mapbox响应服务器如下,我想用spring boot来实现它:

Mapbox 响应标头

Mapbox Content-Type 是application/x-protobuf,如何在 spring boot restfull 应用程序中做到这一点?

4

1 回答 1

1

你可以这样下载

@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);
    }
}
于 2019-12-24T16:31:14.467 回答