Flutter Base64 Encoded String Is Incomplete

2,719

Solution 1

For me base64 is not showing completely. if that the case, print() and debugPrint() both are used for logging in the console. If you are use print() and output is too much at once, then Android sometimes discards some log lines. To avoid this, use debugPrint().

Solution 2

You should convert it to Bytes if you're trying to send it to the backend. This will give you the long string you're looking for ;)

var params = {
      "image_file": base64Encode(_selectedImage.readAsBytesSync()),
    };
Share:
2,719
marvin ralph
Author by

marvin ralph

Updated on December 08, 2022

Comments

  • marvin ralph
    marvin ralph over 1 year

    I'm trying to convert an image byte to base64 encoded string, this operation is successfull but when i print out the encoded string i get the ff:

    /9j/4RgvRXhpZgAASUkqAAgAAAANAAABBAABAAAAQAYAAAEBBAABAAAAsAQAAA8BAgAIAAAAqgAAABABAgAIAAAAsgAAABIBAwABAAAACAAAABoBBQABAAAAugAAABsBBQABAAAAwgAAACgBAwABAAAAAgAAADEBAgANAAAAygAAADIBAgAUAAAA2AAAABMCAwABAAAAAQAAAGmHBAABAAAA7AAAACWIBAABAAAA7gIAAAADAABzYW1zdW5nAFNNLVA1NTUASAAAAAEAAABIAAAAAQAAAFA1NTVYWFUxQ1JBMgAAMjAxOTowMToxNCAwOTozMzoyOAAZAJqCBQABAAAAHgIAAJ2CBQABAAAAJgIAACKIAwABAAAAAgAAACeIAwABAAAAZAAAAACQBwAEAAAAMDIyMAOQAgAUAAAALgIAAASQAgAUAAAAQgIAAAGRBwAEAAAAAQIDAAKSBQABAAAAVgIAAAWSBQABAAAAXgIAAAeSAwABAAAAAgAAAAiSAwABAAAAAAAAAAmSAwABAAAAAAAAAAqSBQABAAAAZgIAAHySBwBiAAAAbgIAAACgBwAEAAAAMDEwMAGgAwABAAAAAQAAAAKgBAABAAAAQAYAAAOgBAABAAAAsAQAAAWgBAABAAAA0AIAABeiAwABAAAAAgAAAAGjBwABAAAAAQAAAAKkAwABAAAAAAAAAAOkAwABAAAAAAAAAAakAwABAAAAAAAAAAAAAAABAAAAFAAAAPAAAABkAAAAMjAxOTowMToxNCAwOTozMzoyOAAyMDE5OjAxOjE0IDA5OjMzOjI4AP0AAABkAAAA/QAAAGQAAADrAAAAZAAAAAcAAQAHAAQAAAAwMTAwA

    An encoded string is supposed to be way more than the characters above. Now when i try to view this by appending data:image/jpeg;base64, to the begin of the encoded string, nothing gets displayed.

    Is flutter cutting the string in the console or what and if yes then how do i get the complete encoded string.