08-18-2022 03:08 AM
Good brothers! I have a problem!
I want to encode the image as Base64. But the base64 string is wrong! It is completely different from the base64 data I encoded on the web page. The data on the web page is correct!
What's wrong with my program? Which VI is used incorrectly?
I put screenshots, source code, correct Base64 data, pictures. Put it down
Thank you for helping me answer
Solved! Go to Solution.
08-18-2022 03:38 AM
Nothing is wrong with base64 encode/decode. You compare different data.
08-18-2022 04:01 AM
Then why do I use the same picture ("1. png") to encode Base64 on the web page online, and the result is different from that of LabVIEW?
08-18-2022 04:08 AM - edited 08-18-2022 04:09 AM
Base64 encoding using the same image:
Results of online page coding: please see the appendix "correct-base64. TXT"
Results of LabVIEW coding: please see the appendix "labview-base64. JPG"
08-18-2022 05:32 AM - edited 08-18-2022 05:45 AM
There's probably an error with the data from the online converter.
Not that the routine is wrong, but the data you paste there might be the wrong encoding or something like that.
I've compared the data in LabVIEW with a completely different Base64 implementation, and that encoding is correct.
You're only telling half the story. "There's no match, so LabVIEW must be wrong".
How did you get the online result?
Looking at the online result, it seems more like the image was compressed before the Base64 encoding. Perhaps a jpg was encoded? Or a compressed png maybe?
Using Base64 Decode and Encode - Online and Base64 Decode and Encode - Online I converted the PNG to Base64 (using files, not copy paste). The data looks like your 'correct' data. However, decoding LabVIEW's result, does result in a valid PNG as well.
It looks to me like Base64 encoding doesn't need to be unique. So there can be more valid encodings for data...
LabVIEW Programming ((make LV more popular, read this)
08-18-2022 07:39 AM
However, decoding LabVIEW's result, does result in a valid PNG as well.
I can confirm this e.g. https://forums.ni.com/t5/LabVIEW/how-to-convert-image-to-base64/m-p/4249877/highlight/false#M1236395
08-18-2022 08:55 AM
I have listened to your views in detail
I agree with you that there are many more effective coding methods
However, because I need to communicate with the network API, I must use the base64 code required by the customer.
I used the encoding website you sent to encode the image "1. PNG".
The result of the website is what I want. (confirmed with the customer that they used Python to Base64 encode the image "1. PNG", and the result is the same as that of the website.)
The result of Base64 encoding in LabVIEW is not what I want.
How can I change my program to make the results of LabVIEW coding consistent with the website?
08-18-2022 09:00 AM
Thank you very much for helping me solve this problem
Do you know why the website code is different from my LabVIEW code?
The website coding is obviously correct (I have verified with the customer, and he used Python to code my pictures, and the results are consistent with the website)
08-18-2022 09:28 AM
As I wrote above, you compare different data.
You must read the 1.png file using the labview function "Read from Binary File". Then encode the read string. This is what your webserver do. This gives the same result as in your "correct-base64.txt" file.
If you decode the PNG file and encode the image using a differnt algorithm, you'll get a different png file.