X Tutup
The Wayback Machine - https://web.archive.org/web/20201028041300/https://github.com/OpenFeign/feign-form/issues/64
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want to get a download stream in the form application / octet-stream. #64

Open
JangCool opened this issue Mar 7, 2019 · 2 comments
Open

Comments

@JangCool
Copy link

@JangCool JangCool commented Mar 7, 2019

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>

@xxlabaza
Copy link
Collaborator

@xxlabaza xxlabaza commented Mar 29, 2019

@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

@rainbow702
Copy link

@rainbow702 rainbow702 commented Jul 25, 2020

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.
X Tutup