Reputation: 11
I want to download images from website using RestAssured. My code:
Response response = given()
.log().all()
.cookie(cookie)
.get(format(image_endpoint, "46581657"));
Endpoint returns status code 200 and image in "application/octet-stream" type. How can I save it as jpg file?
I have tried:
String bin = getImageResponse()
.prettyPrint();
saveFile("foto.jpg", bin); //this method only save string to file
But I cannot open jpg file. How can I save it?
Upvotes: 1
Views: 9836
Reputation: 4929
MIME type application/octet-stream consists of bytes encoded in Base64. Use Base64 class for decoding.
private void saveFile(String path, String octetStream) throws IOException{
byte[] bytes = Base64.getDecoder().decode(octetStream);
try(FileOutputStream fos = new FileOutputStream(path)){
fos.write(bytes);
}
}
I know nothing about RestAssured, so maybe there is any way provided by framework.
Upvotes: 0