Java/Spring에서 이미지를 다운로드하는 예시이다.

byte[]로 다운받고 java.nio.file.Files, Paths를 사용해 다운로드받는다. 


@Service
public class Downloader {

@Autowired
private RestTemplate restTemplate;

public void download(String url) throws Exception {

byte[] binary = restTemplate.getForObject(url, byte[].class);
String fileformat = String.format("image.jpg");
Files.write(Paths.get(fileformat), binary);
}

}


Posted by '김용환'
,