I'm studying downloading files.
I'm looking at the English site, but I don't know what the answer is.
·Return ResponseEntity
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType(contentType))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"resource.getFilename()+"\"")
.body(resource);
https://www.callicoder.com/spring-boot-file-upload-download-rest-api-example/
·Void Return Case
ServletOutputStream outputStream=httpServletResponse.getOutputStram();
https://youtu.be/ryRQ6qXLLYM?t=4401
Either way, the result of the download seems to be the same.
I would appreciate it if you could let me know if you could refer to the website.
The Spring MVC reference describes the handler return values:
According to him,
The former is supported by Spring MVC, and the latter is not supported by the original Servlet API. Generally speaking, I think it is appropriate to use the former method because I use the framework for comfort, but I think it is possible to choose the latter because the behavior of the tailor is contrary to what I want to make. In this case, by using the former, you don't have to write on your own when you write on the stream and close it.ResponseEntity<B>
:
The return value that specifications the full response (including HTTP heads and body) is to be converted through HttpMessageConverter
implements and write to the response.See void
:
Amethod with a void
return type (or null
return value) is considered to have fully handled the response if it has a ServletResponse
, an OutputStream
argument, after @ortSode.@ortSode
© 2024 OneMinuteCode. All rights reserved.