-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Base64 decode not decoding large base64 encoded png images. #33860
Comments
Note that you are decoding a final UriData data = Uri.parse(yourString).data;
print(data.isBase64); // Should print true
print(data.contentAsBytes()); // Would returns your image a Uint8List |
You know that there is no documentation telling us this. |
Could you clarify what exactly is missing from the documentation? When you need to parse a URI then you need to use a Base64Decoder is documented here where it explicitly says “Decoder for base64 encoded data.“ If you have any concrete ideas of how this documentation can be improved please feel free to make a suggestion here or send a PR improving the documentation. |
Reference documentation is pretty useless when there are no examples to show us how the class is used. There are no docs to suggest that we use the Uri.parse class to process a base 64 encoded image. I just assumed I worked pretty much the same way it worked when I generated the image on the server but in reverse. I had actually removed the leading data tag from the image before I attempted to base64 decode the image. It still didn't work. Thanks for the help. The Uri.parse function worked. I just wish the docs had more examples to show us how to use the API. I find issues like this all over the internet when it comes to using different api. It's always a crapshoot as to figuring out what some of these classes are for or even how to use them. |
Did you solve this problem? Today i meet the same quuestion.... |
i have the same issue at using any html viewer library :/ looks like there is newlines/spaces in base64 generated by outlook, but every other technology works like a harm with it :) even html 🤣 |
@Miedziaq you are free to remove new space characters from your string before passing them to We could theoretically add an option to |
Base64 is really annoying to decode because you want to know the size of the decoded output first, so you can allocate a correctly sized If we allow So, I wouldn't want to allow whitespace by default. It could be something you opt in to, getting wither a slower set-up or a larger allocation (and a slower decoding in any case, since you have to check every character for being whitespace). So possible, but not desirable as a generally enabled feature. I'd probably want to do a |
basically yes I can, but if I want to use some html viewer library and pass html to it, (like outlook email or some other) the base64 is only inside img tag, so this is not that easy to read the html file from internet and then remove spaces/newlines only from the img instances. since probably every technology has no problem with it, why this is that problem in flutter/dart... for angular, for html, for c# its doesnt matter if you have this spaces/newlines or not this technology aspire to be very useful and non-problematic, but it is more than others in this topic on example. There is mess, and non informative error messages like in lovely JAVA :> |
so, maybe it will be a good idea to provide overloaded methods for sync and async calls / or some switch to be more strict or less? in basic use its not a really problem to remove this spaces/new lines, but in complicated cases, removing this spaces from the whole html file and generally editing it can be problematic time consuming and slower than just ignore this chars by decoder. maybe I should request this feature to providers of html libraries on flutter? Im passing html file only there and i cannot control it completely.
this works properly only in flutter webview |
It does sound like it is a bug in those packages. If they implement some specification like HTML which is support a different form of Base64 which is more lenient than RFC 4648 then they should not directly pass the data to the |
The current version of dart-lang/sdk I'm using is the one used in flutter.
The decode function throwing an exception. It doesn't matter which Base64 decoder I use.
BASE64.decode()
Base64Decode()
BASE64URL.decode()
None of these functions work properly with larger images.
I've added the image in a pastebin that is generating the problem. https://pastebin.com/tDV4NfPV
The version of dart-lang/sdk is the version used by flutter. I've also tried importing the image using new Image.network. Nothing I do seems to fix this issue.
The exception it is throwing is as follows:
The text was updated successfully, but these errors were encountered: