feign-form
feign-form copied to clipboard
I want to get a download stream in the form application / octet-stream.
hi, I want to get a download stream in the form application / octet-stream or application / octet-stream;charset=UTF-8.
On the Mediator server, called the API server to spring-cloud-open-feign. But I can't get the binary file.
How do I get a binary file with @FeignClient?
--------------------------- Mediator server call ------------------------------
@FeignClient(contextId = "file", name = Const.API_GATEWAY_NAME, url = Const.API_GATEWAY_URL, configuration = FeignConfig.class) @RequestMapping("file") public interface FileClient {
@RequestMapping(value = "/download")
public byte[] download() throws Exception;
} --------------------------- Resource(API) Server download ------------------
public ResponseEntity<ByteArrayResource> download(FileDownload download) throws Exception {
Path path = Paths.get(download.getFilePath());
byte[] data = Files.readAllBytes(path);
ByteArrayResource resource = new ByteArrayResource(data);
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION,
"attachment;filename="
.concat(URLEncoder.encode(download.getOrgFileName(), BaseConst.DEFAULT_CHARSET_UTF_8)))
.contentType(download.getContentType()).contentLength(data.length).body(resource);
}
--------------- JDK1.8 ------------------
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form-spring</artifactId>
<version>3.5.0</version>
</dependency>
@JangCool, please, take a look at the bottom part of the README.md file. There is a section about tf-haotri-pham's feature for downloadable responses
@xxlabaza At the bottom part of the README.md file, it says:
@RequestMapping("/multipart/download/{fileId}")
MultipartFile[] download(@PathVariable("fileId") String fileId);
My question is: At the server side, should it manually create MultipartFile instance as the return value? Or, is there any other way to create the return value? Could you pls give us an simple example. That would be thankful!
well