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

Download file using RestBuilder #15

Open
jojopad opened this issue May 2, 2013 · 4 comments
Open

Download file using RestBuilder #15

jojopad opened this issue May 2, 2013 · 4 comments

Comments

@jojopad
Copy link

jojopad commented May 2, 2013

It would be great to provide support for downloading a file via an InputStream when using the RestBuilder class.

@richardwooding
Copy link

I second this. I'm using RESTBuilder to communicate with JSON-based REST services, but it's failing when I try to download binary files.

@MLoenhardt
Copy link

Would be great for us.

@JohnTheBeloved
Copy link

Need this just now

@Philip-Wu
Copy link

Philip-Wu commented Jan 17, 2017

Here's a workaround on how to do this. I also wrote up more detailed description on my blog:

Blog link

	def void download(String url, OutputStream outputStream) {
		logger.info("url="+url)
				
		RequestCallback requestCallback = new RequestCallback() {
			void doWithRequest(ClientHttpRequest clientRequest) throws IOException {
				clientRequest.headers.add('accept', 'application/octet-stream')
			}
		}
		
		ResponseExtractor responseExtractor = new ResponseExtractor() {
			Object extractData(ClientHttpResponse clientResponse) throws IOException {
				System.out.println('Headers: '+clientResponse.headers)
				outputStream << clientResponse.body
			}
		}
		
		
		RestBuilder rest = new RestBuilder()
		RestTemplate restTemplate = rest.getRestTemplate()
		restTemplate.execute(url, HttpMethod.GET, requestCallback, responseExtractor)						
	}

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

No branches or pull requests

5 participants