2021a base64encode

10 views (last 30 days)
Gregory Bolard
Gregory Bolard on 6 Apr 2021
Answered: Tamas Zsedrovits on 24 May 2022
Hello,
In 2020b, I used to export a figure as png and encode it as base64 string.
When I do the same with 2021a, the 3rd party application receiving the string is not able to restore the png file.
I checked and the same png file is not giving the same string between 2020b and 2021a.
Does anybody understand what happen?
Thank you,
Gregory
  1 Comment
Tulkkas
Tulkkas on 31 Mar 2022
Could you show me what code do you use to export the figure as PNG and then to encore it as based64? It would help me a lot!

Sign in to comment.

Answers (2)

Paulus Mrass
Paulus Mrass on 19 Aug 2021
I had a similar problem that encoding with base64encode "worked" when I created an SVG file with 2020b, but not with 2021a.
In my case the problem was that I used a double vector as input for base64encode. When I converted this double vector into a uint8 vector, and then used this as an input my export worked again and I could create a functional svg file with 2021a.

Tamas Zsedrovits
Tamas Zsedrovits on 24 May 2022
Hello,
I had a similar problem. I dug into the base64encode source code. In my case the root of the problem was the unicode2native function, as it uses the default character set of the user. The default character set was somehow changed from 2020b to 2021a (same computer, same os, same user, same files). You can easily check it with the feature('DefaultCharacterSet') command. In my case for 2020b is windows-1250 and for 2022a is utf-8.
I used the fileread function to read the file from the disk (it was a zip file). The default encoding did not match in this case with the feature('DefaultCharacterSet') for some reason. Although, the fileread help said "When you do not specify any encoding or specify encoding as "", the fileread function uses the default MATLAB encoding to read the file.".
So I set the encoding right for fileread, and ta-daa. It works again.
The old command was: zipfile = matlab.net.base64encode(fileread('zh.zip'));
The new command is: zipfile = matlab.net.base64encode(fileread('zh.zip','encoding',feature('DefaultCharacterSet')));
Best regards,
Tamas

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!