I am using dio package to make a GET request to a server to retrieve a PDF file.
The request is working fine, I get the PDF in base64.
I get the response.data, and I use base64Decode to get the Uint8List, I save the file in the storage.
class FileSaverHelper {
Future<String> save({required String filename, required Uint8List bytes}) async {
final String tempDir = (await getTemporaryDirectory()).path;
final filePath = "$tempDir/$filename";
await File(filePath).writeAsBytes(bytes);
return filePath;
}
}
class OpenFileHelper {
final FileSaverHelper fileSaverHelper = Get.find();
Future<void> open({
required String filename,
required Future<Uint8List> Function() onDownload
}) async {
final Uint8List bytes = await onDownload();
final filePath = await fileSaverHelper.save(
filename: filename,
bytes: bytes
);
if(await File(filePath).exists()){
OpenFilex.open(filePath);
}
}
}
When I open the PDF it has only the first page and when I test the base64 that the server sends in the site Base64 to PDF, the PDF decoded has the amount of pages correctly (which is two).
Why after I use base64Decode(response.data), save the PDF to the storage, open it, it has only the first page but in the site the amount of pages is correct?
I found the problem is with the GET request, since the base64 retrieve by the server only through flutter, the file is retrieved incomplete.