I want to download a binary file which is PDF and save it into my device. The file comes from API response. My response.body
is like this:
Here is my code:
void downloadFile() async {
String url = Uri.encodeFull('https://API_URL');
http.Response response = await http.post(url, headers: {"Accept": "application/json", HttpHeaders.authorizationHeader: 'Bearer '},});
print(response.body);
}
How can I use response.body
to download the PDF file?
response.bodyBytes
is the binary data.body
is the same data already passed through a character recorder. The default is Latin 1 unless the content type header included an encoding parameter.