I need to upload a PDF file to the server.
I use this code.
void pickFiles() async {
try {
final result = await FilePicker.platform.pickFiles(
allowMultiple: false,
type: FileType.custom,
withData: true,
allowedExtensions: ['pdf'],
);
Uint8List? fileBytes = result!.files.first.bytes;
base64String = base64Encode(fileBytes!);
nameDocumentController.text = result.files.first.name;
} on PlatformException catch (e) {
debugPrint('Unsupported operation$e');
} catch (e) {
debugPrint(e.toString());
}
}
I don't understand why this code doesn't work. On the server I find the file but with 0 bytes
I tried all the examples online but in the end base64String is always empty.
Where can I find a working example?
Thanks
Biagio